0
我有從ImmutableJS Record對象和我想要的元件推到使用withMutations
這樣內記錄屬性stack
的數組:如何正確PUSH/POP的元素內記錄的陣列ImmutableJS
/* eslint-disable new-cap */
const InitialState = Record({
isOpen: true,
item: null,
type: '',
stack: []
});
/* eslint-enable new-cap */
const initialState = new InitialState;
export default function modal(state = initialState, action) {
...
return state.withMutations((ctx) => {
const newStack = ctx.get('stack');
newStack.push({
item: action.item,
type: action.type
});
ctx.set('isOpen', true)
.set('item', action.item)
.set('type', action.type)
.set('stack', newStack);
});
});
但是,這似乎在記錄中未設置stack
屬性。 當我這樣做時,它正確地將數組設置爲stack
。
return state.withMutations((ctx) => {
ctx...
.set('stack', [{
item: action.item,
type: action.type
}]);
});
因此,
兩個問題
A.如何設置stack
屬性與數組?
B.如何在ImmutableJS中將一個push/pop對象push到數組中?