将值附加到List

时间:2016-11-14 13:30:17

标签: immutable.js

我在Map对象中有一个不可变的列表对象,如下所示:

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

如何将值附加到" myList",从而更新state

2 个答案:

答案 0 :(得分:16)

您可以使用update()方法。

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

const updatedState = state.update('myList', myList => myList.push('some value'));

答案 1 :(得分:2)

emails = List(new Array<string>());
defaultValues = ['gold@gmail.com', 'saphire@gmail.com'];
this.emails = this.emails.push(...this.defaultValues);

这是打字稿。