Skip to content

Commit

Permalink
refactor(trace): change node field names
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Aug 5, 2021
1 parent 2d9cbda commit bdfef62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions extensions/trace/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
clone,
isArray,
isObject,
toPath,
} from '@harlem/utilities';

import type {
Expand Down Expand Up @@ -51,16 +52,22 @@ function defaultCallback<TValue extends object>(
callback: TraceCallback<TValue>,
gate: TraceGate<TValue>,
paths: PropertyKey[],
key: PropertyKey,
prop: PropertyKey,
oldValue: unknown,
newValue?: unknown,
) {
try {
const nodes = paths.slice();

callback({
gate,
nodes,
prop,
newValue,
paths: paths.concat(key),
oldValue: newValue === oldValue ? oldValue : clone(oldValue),
get path() {
return toPath(nodes.concat(prop));
},
});
} catch {
console.warn('Trace callback failed');
Expand Down
4 changes: 3 additions & 1 deletion extensions/trace/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export interface TraceOptions<TValue extends object> {
}

export interface TraceResult<TValue extends object> {
readonly path: string;
gate: TraceGate<TValue>;
paths: PropertyKey[];
nodes: PropertyKey[];
prop: PropertyKey;
oldValue: unknown;
newValue: unknown;
}
Expand Down

0 comments on commit bdfef62

Please sign in to comment.