Last active
October 29, 2016 20:20
-
-
Save JoeKarlsson/03e11995ca943f9d00380f36fb888629 to your computer and use it in GitHub Desktop.
Immutable JS demo
This file contains 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 Immutable = require('immutable'); | |
const data = Immutable.Map({ | |
people: Immutable.List(['Joe', 'Ray', 'Nigel']), | |
test: 'Hello World' | |
}) | |
const data2 = data.updateIn(['people'], ((people) => { | |
return people.set(0, 'Russel'); | |
})); | |
console.log('data2: ', data2); | |
// Copy an array Vanilla JS | |
var old = ["Apples", "Bananas"]; | |
var newArr = old.slice(0); | |
console.log('newArr: ', newArr); | |
//or | |
var newArr2 = [...old]; | |
console.log('newArr2: ', newArr2); | |
// Copy an object in vanilla JS | |
let oldObj = { | |
name: 'Joe', | |
favColor: 'Green', | |
} | |
var newObj = Object.assign({}, oldObj); | |
console.log('newObj: ', newObj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment