Skip to content

Commit

Permalink
fix(paths): fix setIn fast paths for path length 3/4
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 18, 2018
1 parent 2376e02 commit 92f0e27
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/paths/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export function getter(path: Path) {
*/
export function setter(path: Path) {
const ks = toPath(path);
// (s, v) => ({ ...s, [k]: f((s || {})[k], v) });
let [a, b, c, d] = ks;
switch (ks.length) {
case 0:
Expand All @@ -146,9 +145,9 @@ export function setter(path: Path) {
case 2:
return (s, v) => ({ ...s, [a]: { ...s[a], [b]: v } });
case 3:
return (s, v) => ({ ...s, [a]: { ...s[a], [b]: { ...s[b], [c]: v } } });
return (s, v) => ({ ...s, [a]: { ...(s = s[a]), [b]: { ...s[b], [c]: v } } });
case 4:
return (s, v) => ({ ...s, [a]: { ...s[a], [b]: { ...s[b], [c]: { ...s[c], [d]: v } } } });
return (s, v) => ({ ...s, [a]: { ...(s = s[a]), [b]: { ...(s = s[b]), [c]: { ...s[c], [d]: v } } } });
default:
const kl = ks[ks.length - 1];
let f = (s, v) => ({ ...(s || {}), [kl]: v });
Expand Down

0 comments on commit 92f0e27

Please sign in to comment.