本文整理汇总了TypeScript中Immutable.Map.withMutations方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Map.withMutations方法的具体用法?TypeScript Map.withMutations怎么用?TypeScript Map.withMutations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Immutable.Map
的用法示例。
在下文中一共展示了Map.withMutations方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: onFetchNext
onFetchNext(currentState: Map<string, any>, jokes: List<any>): Map<string, any> {
return currentState.withMutations(state => {
state
.set('loading', false)
.set('jokes', fromJS(jokes));
});
}
示例2: dispatch
private dispatch(eventName, ...args) {
let actionArgs = args.slice(0, -1);
actionArgs.unshift(this.canonical, this.local);
let callback = args[args.length - 1];
let result = callback.apply(null, actionArgs);
let {canonical, local} = result;
this.cacheMap = this.cacheMap.withMutations(cacheMap => {
if (canonical) {
cacheMap.set(CANONICAL, canonical);
}
if (local) {
cacheMap.set(LOCAL, local);
}
});
this.canonical.cacheMap = this.cacheMap;
this.local.cacheMap = this.cacheMap;
}
示例3: reducer
function reducer(state: IReduxState = initial, { type, payload }: IAction): IReduxState {
const imState: Map<string, any> = fromJS(state);
switch (type) {
case 'CREATE_POLL:CHANGE_FIELD_VALUE': {
interface IData { fieldName: string; fieldValue: string; }
const data: IData = payload as IData;
return imState
.setIn(['newPoll', data.fieldName], data.fieldValue)
.toJS();
}
case 'CREATE_POLL:ADD_ANSWER': {
const index: number = payload as number;
const questions: List<Map<string, any>> = imState.getIn(['newPoll', 'questions']);
const question: Map<string, any> = questions.get(index);
return imState
.setIn(
['newPoll', 'questions'],
questions.set(index, question.set('answers', question.get('answers').push(initialAnswer))),
).toJS();
}
case 'CREATE_POLL:ADD_QUESTION': {
return imState.setIn(
['newPoll', 'questions'],
(imState.getIn(['newPoll', 'questions']) as List<IEditableQuestion>).push(initialQuestion),
).toJS();
}
case 'CREATE_POLL:CHANGE_ANSWER_TEXT': {
interface IData { questionIndex: number; answerIndex: number; value: string; }
const data: IData = payload as IData;
const questions = imState.getIn(['newPoll', 'questions']);
const question = questions.get(data.questionIndex);
const answers = question.get('answers');
const answer = answers.get(data.answerIndex);
return imState.withMutations((mutable: Map<string, any>) => mutable.setIn(
['newPoll', 'questions'],
questions.set(
data.questionIndex,
question.set('answers', answers.set(data.answerIndex, answer.set('text', data.value))),
),
)).toJS();
}
case 'CREATE_POLL:CHANGE_QUESTION_FIELD': {
interface IData { questionIndex: number; value: string; fieldName: string; }
const data = payload as IData;
const questions = imState.getIn(['newPoll', 'questions']);
return imState.setIn(
['newPoll', 'questions'],
questions.set(
data.questionIndex,
questions.get(data.questionIndex).set(data.fieldName, data.value),
),
).toJS();
}
case 'CREATE_POLL:SEND_NEW_POLL_SUCCESS':
return imState.set('newPoll', initial.newPoll).toJS();
case 'CREATE_POLL:LOAD_POLL_SUCCESS':
return imState.set('newPoll', payload).toJS();
case 'CREATE_POLL:CLEAR_DATA':
return imState.set('newPoll', initial.newPoll).toJS();
default:
return state;
}
}