Skip to content

Commit

Permalink
fix(ValueObject): fix types, param name
Browse files Browse the repository at this point in the history
  • Loading branch information
slikts committed Feb 23, 2020
1 parent 8714127 commit 4789bad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/DeepCompositeSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { isObject } from './helpers';
* an object's entries (key-value pairs).
*/
// tslint:disable-next-line: variable-name
const DeepCompositeSymbol = ((object: any, filter?: (entry: [string, any]) => boolean) => {
const DeepCompositeSymbol = (object: any, filter?: (entry: [string, any]) => boolean) => {
const entries = filter ? Object.entries(object).filter(filter) : Object.entries(object);
// Recursively replace non-tuple object values with tuples
entries.forEach(x => update(x, filter));
entries.forEach(entry => update(entry, filter));
return Tuple.unsafeSymbol(...flatten(entries));
}) as any;
};

const update = (entry: any, filter?: any) => {
const v = entry[1];
Expand Down
7 changes: 5 additions & 2 deletions src/ValueObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import DeepCompositeSymbol from './DeepCompositeSymbol';
* https://github.com/tc39/proposal-record-tuple
*/
// tslint:disable-next-line: variable-name
const ValueObject = <A extends object>(object: A, keyFilter?: (key: string) => boolean): A => {
const key = DeepCompositeSymbol(object, keyFilter);
const ValueObject = <A extends object>(
object: A,
filter?: (entry: [string, any]) => boolean,
): A => {
const key = DeepCompositeSymbol(object, filter);
if (cache.has(key)) {
return cache.get(key) as A;
}
Expand Down

0 comments on commit 4789bad

Please sign in to comment.