This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const shields = { | |
soccer: { | |
'AS Monaco': 'https://i.imgur.com/R0LjeFU.png', | |
'Besiktas': 'https://i.imgur.com/zAhnhFt.png', | |
'Milan': 'https://i.imgur.com/WiOPhXt.png' | |
}, | |
baseball: { | |
'Los Angeles Dodgers': 'https://i.imgur.com/bB0HYgb.png', | |
'Houston Astros': 'https://i.imgur.com/gwR11oB.png' | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add item to array | |
// use concat or spread operator | |
// Remove item from array | |
// user slice | |
// Replace item in array | |
// | |
// Source: https://egghead.io/lessons/javascript-redux-avoiding-array-mutations-with-concat-slice-and-spread |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To remove an item from an array by id: | |
return state.filter(item => item.id !== action.id) | |
// To remove a key from an object by id: | |
let copy = Object.assign({}, state) // assuming you use Object.assign() polyfill! | |
delete copy[action.id] // shallowly mutating a shallow copy is fine | |
return copy | |
// (Bonus) The same with object spread operator proposal: |