Changing an object is about changing properties on it as well as adding properties to it. First off, let's look at how to change existing values:
// core-concepts/object.js
// the old way
let anakin = { name: "anakin" };
anakin.name = "darth";
console.log(anakin);
// the Redux way
let anakinRedux = { name: "anakin" };
let darth = Object.assign({}, anakinRedux, { name: "darth" });
console.log(anakinRedux);
console.log(darth);
That covers the existing case. What about adding a new property? We can do that like so:
// core-concepts/object-add.js
// the old way
let anakin = { name: "anakin" };
console.log("anakin", anakin);
anakin["age"] = "17";
console.log("anakin with age", anakin);
// the Redux way
let anakinImmutable = { name: "anakin" };
let anakinImmutableWithAge = Object.assign({}, anakinImmutable, { age: 17 });
console.log("anakin redux", anakinImmutable);
console.log("anakin redux with age", anakinImmutableWithAge);