Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append value to List

Tags:

immutable.js

I have a immutable list object, within a Map object, as follows:

let initialState = Immutable.fromJS({});
state = initialState;
state = state.set("myList", Immutable.List());

How do I append a value to "myList", thereby updating state?

like image 230
Baz Avatar asked Nov 14 '16 13:11

Baz


2 Answers

emails = List(new Array<string>());
defaultValues = ['[email protected]', '[email protected]'];
this.emails = this.emails.push(...this.defaultValues);

This is for typescript .

like image 175
I.Tyger Avatar answered Nov 19 '22 11:11

I.Tyger


You can use update() method.

const initialState = Immutable.fromJS({});
const state = initialState.set('myList', Immutable.List()); 

const updatedState = state.update('myList', myList => myList.push('some value'));
like image 41
caspg Avatar answered Nov 19 '22 13:11

caspg