DEV Community

Discussion on: Tidy Redux Reducers with Lodash FP

Collapse
 
briancodes profile image
Brian • Edited

One thing I noticed with lodash/fp set, it behaves in an immutable fashion but just for the objects in the branch it touches - it's probably not a big deal, but good to know:-)

const originalObject = {
  account: {
    id: '1'
  }, 
  address: {
    zip: '123'
  }
};
const updated = fp.set("account.id", '2', originalObject);
console.log(
  updated,
  originalObject === updated, // false
  originalObject.account === updated.account, // false
  originalObject.address === updated.address // true
);
Enter fullscreen mode Exit fullscreen mode