Skip to content

Commit

Permalink
feat(valueobject): add a symbol to mark objects as not deeply comparable
Browse files Browse the repository at this point in the history
The main use case is to avoid getting stuck on circular references.
  • Loading branch information
slikts committed Feb 23, 2020
1 parent 4789bad commit 38e8603
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/DeepCompositeSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ const DeepCompositeSymbol = (object: any, filter?: (entry: [string, any]) => boo
return Tuple.unsafeSymbol(...flatten(entries));
};

const update = (entry: any, filter?: any) => {
const v = entry[1];
if (isObject(v) && !(v instanceof Tuple)) {
entry[1] = DeepCompositeSymbol(v, filter);
export const shallow = Symbol('shallow');

const update = (entry: [string, any], filter?: any) => {
const value = entry[1];
if (!value[shallow] && isObject(value) && !(value instanceof Tuple)) {
entry[1] = DeepCompositeSymbol(value, filter);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/tuplerone.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { unsafe, tuple, unsafeSymbol, symbol } from './Tuple';
import DeepCompositeSymbol from './DeepCompositeSymbol';
import DeepCompositeSymbol, { shallow } from './DeepCompositeSymbol';
import ValueObject from './ValueObject';

export { symbol as CompositeSymbol } from './Tuple';
Expand Down

0 comments on commit 38e8603

Please sign in to comment.