本文整理匯總了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;
}
}