本文整理汇总了TypeScript中@riim/map-set-polyfill.Map.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Map.get方法的具体用法?TypeScript Map.get怎么用?TypeScript Map.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@riim/map-set-polyfill.Map
的用法示例。
在下文中一共展示了Map.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: handleEvent
handleEvent(evt: IEvent) {
let events = this._events.get(evt.type);
if (!events) {
return;
}
if (Array.isArray(events)) {
let eventCount = events.length;
if (eventCount == 1) {
if (this._tryEventListener(events[0], evt) === false) {
evt.propagationStopped = true;
}
} else {
events = events.slice();
for (let i = 0; i < eventCount; i++) {
if (this._tryEventListener(events[i], evt) === false) {
evt.propagationStopped = true;
}
}
}
} else if (this._tryEventListener(events, evt) === false) {
evt.propagationStopped = true;
}
}
示例2: _on
_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]);
}
}
}
示例3:
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;
}
示例4: 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;
}
示例5: discard
discard(typeName: string, id?: any): boolean {
let types = this._types.get(typeName);
if (types && types.size) {
if (arguments.length == 1) {
types.clear();
return true;
}
return types.delete(id);
}
return false;
}
示例6: emit
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;
}
示例7: _off
_off(type: string, listener: TListener, context: any) {
let index = type.indexOf(':');
if (index != -1) {
let propName = type.slice(index + 1);
(this[propName + 'Cell'] || (this[propName], this[propName + 'Cell'])).off(
type.slice(0, index),
listener,
context
);
} else {
let events = this._events.get(type);
if (!events) {
return;
}
let evt;
if (!Array.isArray(events)) {
evt = events;
} else if (events.length == 1) {
evt = events[0];
} else {
for (let i = events.length; i; ) {
evt = events[--i];
if (evt.listener == listener && evt.context === context) {
events.splice(i, 1);
break;
}
}
return;
}
if (evt.listener == listener && evt.context === context) {
this._events.delete(type);
}
}
}
示例8: getEvents
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;
}
示例9: 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;
}
示例10: get
get(typeName: string, id?: any | Array<any>): EventEmitter | Array<EventEmitter | null> | null {
let types = this._types.get(typeName);
return Array.isArray(id)
? id.map(id => (types && types.get(id)) || null)
: (types && types.get(id)) || null;
}