Skip to content

Commit

Permalink
fix(readme): small README fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
grantila committed Sep 10, 2020
1 parent 54a2b29 commit 5723152
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -8,9 +8,9 @@

# instead

`instead` is a *deep-replace* feature which is value-wise equivalent to the expression `a = b`. But unlike pure assignment, or `Object.assign()` or any of the *deep-assign* packages, `instead` replaces values, object properties and array items with the new value, only if they differ.
`instead` is a *deep-replace* function which is value-wise equivalent to the expression `a = b` but expressed as `a = instead( a, b )`. However, unike pure assignment, or `Object.assign()` or any of the *deep-assign* packages, `instead` replaces values, object properties and array items with the new value, only if they differ.

If `a` and `b` serializes to the exact same, `(a = b) === b` is true, but `instead(a, b) === a`.
If `a` and `b` serializes to the exact same, `(a = b) === b`, but `instead(a, b) === a`.

This is sometimes extremely handy when referencial equality matters, especially when equality can optimize away unnecessary logic, such as in React.

Expand All @@ -24,7 +24,7 @@ const incomingValue = {
foo: { b: 1 },
bar: { c: 3 },
};
const newValue = instead( a, b );
const newValue = instead( previousValue, incomingValue );
// Incoming {.foo} is equivalent to previous {.foo}, so reference is kept:
( newValue.foo === previousValue.foo ); // true
( newValue.bar === incomingValue.bar ); // true
Expand Down
2 changes: 0 additions & 2 deletions lib/index.ts
Expand Up @@ -77,8 +77,6 @@ export function instead< T >( target: T, source: T ): T
);
const extraSourceKeys = difference( sourceKeys, targetKeys );
const newTarget = bothKeys.length < targetKeys.length;
// // @ts-ignore
// console.log("bothKeys.length < targetKeys.length", bothKeys.length, targetKeys.length)
const maybeNewTarget = newTarget ? { } as T : target;

for ( const key of bothKeys )
Expand Down

0 comments on commit 5723152

Please sign in to comment.