本文整理汇总了TypeScript中Immutable.Map.set方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Map.set方法的具体用法?TypeScript Map.set怎么用?TypeScript Map.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Immutable.Map
的用法示例。
在下文中一共展示了Map.set方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: reducer
function reducer(state: IReduxState = initial, { type, payload }: IAction): IReduxState {
const imState: Map<string, any> = fromJS(state);
switch (type) {
case 'VIEW_POLLS:LOAD_POLLS_SUCCESS':
return imState.set('polls', payload).toJS();
case 'VIEW_POLLS:LOAD_POLL_SUCCESS': {
interface IData { results: IPollResult[]; poll: IPoll; }
const data = payload as IData;
return imState.set('selectedPoll', data).toJS();
}
case 'VIEW_POLLS:SELECT_ANSWER': {
interface IData { questionIndex: number; answerIndex: number; }
const data = payload as IData;
const questions = imState.getIn(['selectedPoll', 'poll', 'questions']);
const question = questions.get(data.questionIndex);
return imState.setIn(
['selectedPoll', 'poll', 'questions', data.questionIndex],
question.set('answers', question.get('answers').map(
(answer: Map<string, any>, index: number) => answer.set('isSelected', index === data.answerIndex),
)),
).toJS();
}
default: return state;
}
}
示例2: referencedModels
export function referencedModels(
project: Project,
mod: Module,
all?: Map<string, ModelDef>,
): Map<string, ModelDef> {
if (!all) {
all = Map();
}
const mdl = defined(project.model(mod.modelName));
const name = mdl.ident;
if (all.has(name)) {
const def = defined(all.get(name)).update('modules', (modules: Set<Module>) =>
modules.add(mod),
);
all = all.set(name, def);
} else {
all = all.set(
name,
new ModelDef({
model: mdl,
modules: Set<Module>([mod]),
}),
);
}
for (const [name, module] of mdl.modules) {
all = referencedModels(project, module, all);
}
return all;
}
示例3: addNode
addNode(node: any) {
var nodes = this.nodes.push(node);
var children = this.children.set(node.id, List<any>());
var parents = this.parents.set(node.id, List<any>());
return new Graph(nodes, children, parents);
}
示例4: removeConnection
removeConnection(parent: any, child: any) {
var parents = this.parents.get(child.id);
var parentsAll = this.parents.set(child.id, parents.filter(ancestor => ancestor !== parent).toList());
var children = this.children.get(parent.id);
var childrenAll = this.children.set(parent.id, children.filter(ch => ch !== child).toList());
return new Graph(this.nodes, childrenAll, parentsAll);
}
示例5: it
it('can progressively add items known to collide', () => {
// make a big map, so it hashmaps
var map: Map<any, any> = Range(0, 32).toMap();
map = map.set('@', '@');
map = map.set(64, 64);
map = map.set(96, 96);
expect(map.size).toBe(35);
expect(map.get('@')).toBe('@');
expect(map.get(64)).toBe(64);
expect(map.get(96)).toBe(96);
});
示例6: constructor
constructor() {
this.container = new EmptyObject();
this.referenceMap = new EmptyObject();
this.referenceMap[CANONICAL] = new EmptyObject();
this.referenceMap[LOCAL] = new EmptyObject();
this.cacheMap = Map<string, Map<string, any>>();
this.cacheMap = this.cacheMap.set(CANONICAL, cacheData());
this.cacheMap = this.cacheMap.set(LOCAL, cacheData());
this.canonical = new Cache(this.cacheMap, CANONICAL);
this.local = new Cache(this.cacheMap, LOCAL);
}
示例7: serversChannelsRelation
function serversChannelsRelation(state: Map<ServerId, List<ChannelId>> = Map<ServerId, List<ChannelId>>(), action: Action): Map<ServerId, List<ChannelId>> {
switch (action.type) {
case ActionType.ADD_SERVER:
return state.set(action.payload.server.id, List<ChannelId>())
case ActionType.ADD_CHANNEL:
let channel: Channel = action.payload.channel
return state.set(channel.serverId, state.get(channel.serverId).push(channel.id))
default:
return state
}
}
示例8: removeNode
removeNode(node: any) {
var nodesAll = this.nodes.filter(n => n !== node).toList();
var parentsAll: Map<number, List<Node>> = this.parents;
var childrenAll: Map<number, List<Node>> = this.children;
var parents = parentsAll.get(node.id);
parents.forEach((parent) => {
var children = childrenAll.get(parent.id);
children = children.filter((child) => child !== node).toList();
childrenAll = childrenAll.set(parent.id, children);
});
parentsAll = parentsAll.set(node.id, List<any>());
var children = childrenAll.get(node.id);
children.forEach((child) => {
var parents = parentsAll.get(child.id);
parents = parents.filter((ancestor) => ancestor !== node).toList();
parentsAll = parentsAll.set(child.id, parents);
});
childrenAll = childrenAll.remove(node.id);
return new Graph(nodesAll, childrenAll, parentsAll);
}
示例9: updateFromModel
export function updateFromModel(modelMap: Map<string, any>, updateObject: any) {
for (var key in updateObject) {
if (updateObject.hasOwnProperty(key)) {
modelMap.set(key, updateObject[key]);
}
}
}
示例10: set
set(key: string, order: SortingOrder, forceUpdate = true) {
this.checkKey(key)
this.checkOrder(order)
this.states = this.states.set(key, order)
this.notifyUpdate(forceUpdate)
return this
}