Skip to content

Instantly share code, notes, and snippets.

@JoeKarlsson
Last active October 29, 2016 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoeKarlsson/03e11995ca943f9d00380f36fb888629 to your computer and use it in GitHub Desktop.
Save JoeKarlsson/03e11995ca943f9d00380f36fb888629 to your computer and use it in GitHub Desktop.
Immutable JS demo
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