本文整理汇总了TypeScript中@riim/map-set-polyfill.Map类的典型用法代码示例。如果您正苦于以下问题:TypeScript Map类的具体用法?TypeScript Map怎么用?TypeScript Map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Map类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: set
set(typeName: string, type: EventEmitter): this {
let types = this._types.get(typeName);
if (!types) {
types = new Map<any, EventEmitter>();
this._types.set(typeName, types);
}
types.set((type as any).id, type);
return this;
}
开发者ID:Riim,项目名称:StoreX,代码行数:12,代码来源:StoreX.ts
示例2: isObjectOrArray
push<T = any>(data: any): T {
if (Array.isArray(data)) {
let list = [] as Array<any>;
for (let i = 0, l = data.length; i < l; i++) {
let value = data[i];
list[i] = isObjectOrArray(value) ? this.push(value) : value;
}
return list as any;
}
let typeName = data.__type;
if (typeName) {
let typeConstructor = this._typeConstructors.get(typeName);
if (!typeConstructor) {
throw new TypeError(`Type "${typeName}" is not defined`);
}
let types = this._types.get(typeName);
if (!types) {
types = new Map<any, EventEmitter>();
this._types.set(typeName, types);
}
let id = data.id;
let type = types.get(id);
if (!type) {
type = new typeConstructor();
types.set(id, type);
}
for (let name in data) {
if (name != '__type') {
let value = data[name];
if (value && typeof value == 'object') {
if (Object.getPrototypeOf(value) === ObjectProto) {
value = this.push(value);
if (Object.getPrototypeOf(value) === ObjectProto) {
value = new ObservableMap(value);
}
} else if (Array.isArray(value)) {
value = new ObservableList(this.push(value) as Array<any>);
}
}
(type as any)[name] = value;
}
}
return type as any;
}
let dataCopy = {} as { [name: string]: any };
for (let name in data) {
let value = data[name];
dataCopy[name] = isObjectOrArray(value) ? this.push(value) : value;
}
return dataCopy as any;
}
开发者ID:Riim,项目名称:StoreX,代码行数:68,代码来源:StoreX.ts
示例3: if
_on(type: string, listener: TListener, context: any) {
let index = type.indexOf(':');
if (index != -1) {
let propName = type.slice(index + 1);
currentlySubscribing = true;
(this[propName + 'Cell'] || (this[propName], this[propName + 'Cell'])).on(
type.slice(0, index),
listener,
context
);
currentlySubscribing = false;
} else {
let events = this._events.get(type);
let evt = { listener, context };
if (!events) {
this._events.set(type, evt);
} else if (Array.isArray(events)) {
events.push(evt);
} else {
this._events.set(type, [events, evt]);
}
}
}
开发者ID:Riim,项目名称:cellx,代码行数:26,代码来源:EventEmitter.ts
示例4: TypeError
emit(
evt:
| {
target?: EventEmitter;
type: string;
bubbles?: boolean;
defaultPrevented?: boolean;
propagationStopped?: boolean;
data?: {
[name: string]: any;
};
}
| string,
data?: { [name: string]: any }
): IEvent {
if (typeof evt == 'string') {
evt = {
target: this,
type: evt
};
} else if (!evt.target) {
evt.target = this;
} else if (evt.target != this) {
throw new TypeError('Event cannot be emitted on this object');
}
if (data) {
evt.data = data;
}
if (transactionLevel) {
let events = transactionEvents.get(this);
if (!events) {
events = Object.create(null) as { [type: string]: IEvent };
transactionEvents.set(this, events);
}
(evt.data || (evt.data = {})).prev = events[evt.type] || null;
events[evt.type] = evt as IEvent;
} else {
this.handleEvent(evt as IEvent);
}
return evt as IEvent;
}
开发者ID:Riim,项目名称:cellx,代码行数:46,代码来源:EventEmitter.ts
示例5:
getAll<T extends EventEmitter = EventEmitter>(typeName: string): Array<T> {
let types = [] as Array<T>;
((this._types.get(typeName) || []) as Array<T>).forEach(type => {
types.push(type);
});
return types;
}
开发者ID:Riim,项目名称:StoreX,代码行数:9,代码来源:StoreX.ts
示例6:
getEvents(type?: string) {
let events: any;
if (type) {
events = this._events.get(type);
if (!events) {
return [];
}
return Array.isArray(events) ? events : [events];
}
events = Object.create(null);
this._events.forEach((typeEvents, type) => {
events[type] = Array.isArray(typeEvents) ? typeEvents : [typeEvents];
});
return events;
}
开发者ID:Riim,项目名称:cellx,代码行数:21,代码来源:EventEmitter.ts
注:本文中的@riim/map-set-polyfill.Map类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论