obj1 = { internal: {} }; Object.freeze(obj1); obj1.internal.a = 'aValue'; obj1.internal.a // 'aValue' // To make obj fully immutable, freeze each object in obj. // To do so, we use this function. function deepFreeze(obj) { // Retrieve the propert…
With ECMAScript 6 now feature complete, any further changes to the core of JavaScript will happen in ECMAScript 7. I’m pretty excited about the changes coming in ECMAScript 6 and there are already some great ECMAScript 7 features such as Object.obser…
In the previous lesson we created a reducer that can handle two actions, adding a new to-do, and toggling an existing to-do. Right now, the code to update the to-do item or to create a new one is placed right inside of the to-dos reducer. This functi…
Learn how to implement toggling a todo in a todo list application reducer. let todo = (state = [], action) => { switch(action.type){ case 'ADD_ITEM': return state = [ ...state, { text: action.text, id: action.id, completed: false } ]; case 'TOGGLE_IT…
Learn how to implement adding a todo in a todo list application reducer. let todo = (state = [], action) => { switch(action.type){ case 'ADD_ITEM': return state = [ ...state, { text: action.text, id: action.id, completed: false } ]; default: return s…
Learn how to use Object.assign() and the spread operator proposed for ES7 to avoid mutating objects. /* * Open the console to see * that the tests have passed. */ const toggleTodo = (todo) => { return { ...todo, completed: !todo.completed }; }; const…
For Redux, you cannot use mutable methods like push, splice. Need to use immutable methods such as concat, slice and ...spread Html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Bin</title> &…