当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Map.set方法代码示例

本文整理汇总了TypeScript中@riim/map-set-polyfill.Map.set方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Map.set方法的具体用法?TypeScript Map.set怎么用?TypeScript Map.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@riim/map-set-polyfill.Map的用法示例。


在下文中一共展示了Map.set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: _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]);
			}
		}
	}
开发者ID:Riim,项目名称:cellx,代码行数:26,代码来源:EventEmitter.ts

示例2: 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

示例3: 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;
	}
开发者ID:Riim,项目名称:cellx,代码行数:46,代码来源:EventEmitter.ts

示例4: 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


注:本文中的@riim/map-set-polyfill.Map.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。