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


TypeScript WeakMap.get函数代码示例

本文整理汇总了TypeScript中dojo-shim/WeakMap.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: factory

		let registryHandle = widgets.get(app).register(id, () => {
			const promise = Promise.resolve().then(() => {
				// Always call the factory in a future turn. This harmonizes behavior regardless of whether the
				// factory is registered through this method or loaded from a definition.

				const { registryProvider, defaultStore } = app;
				interface Options {
					id: string;
					registryProvider: RegistryProvider;
					stateFrom?: StoreLike;
				}
				const options: Options = { id, registryProvider };
				if (defaultStore) {
					options.stateFrom = defaultStore;
				}
				return factory(options);
			}).then((widget) => {
				if (!destroyed) {
					instanceHandle = app._instanceRegistry.addWidget(widget, id);
				}

				return widget;
			});
			// Replace the registered factory to ensure next time this widget is needed, the same widget is returned.
			registryHandle.destroy();
			registryHandle = widgets.get(app).register(id, () => promise);
			return promise;
		});
开发者ID:datafordevelopment,项目名称:dojo-frame,代码行数:28,代码来源:createApp.ts

示例2:

					.subscribe((series) => {
						privateStateMap.get(instance).series = series;
						// invalidate() is typed as being optional, but that's just a workaround until
						// <https://github.com/dojo/compose/issues/74> is in place. Silence the strict null check
						// violation for now.
						instance.invalidate!();
					});
开发者ID:novemberborn,项目名称:dojo2-dataviz,代码行数:7,代码来源:createColumnPlotMixin.ts

示例3: Promise

		return new Promise((resolve) => {
			handlesWeakMap.get(this).forEach((handle) => {
				handle && handle.destroy && handle.destroy();
			});
			this.destroy = noop;
			this.own = destroyed;
			resolve(true);
		});
开发者ID:jdonaghue,项目名称:compose,代码行数:8,代码来源:createDestroyable.ts

示例4: function

	return function(this: any, ...args: any[]) {
		const store = this;
		const state = instanceStateMap.get(store);
		if (!state || this.source) {
			return operation.apply(store, args);
		}
		if (!state.inProgress) {
			state.inProgress = true;
			setTimeout(function() {
				processNext(state);
			});
		}
		if (returnsPromise) {
			return new Promise(function(resolve, reject) {
				state.operationQueue.push(function() {
					return operation.apply(store, args).then(function(results: any) {
						resolve(results);
					}, function(error: any) {
						reject(error);
					});
				});
			});
		}
		else {
			let pushed = false;
			let observers: Observer<any>[] = [];
			let operationObservable: Observable<any>;
			const observable = createStoreObservable(
				new Observable(function subscribe(observer: Observer<{}>) {
					if (!operationObservable) {
						observers.push(observer);
					}
					else {
						operationObservable.subscribe(observer);
					}
					if (!pushed) {
						state.operationQueue.push(function() {
							operationObservable = operation.apply(store, args);
							observers.forEach(function(observer) {
								operationObservable.subscribe(observer);
							});
							return operationObservable.toPromise();
						});
						pushed = true;
					}

					return () => observers.splice(observers.indexOf(observer), 1);
				}),
				function(updateResults: UpdateResults<{}>) {
					return updateResults.successfulData;
				}
			);
			observable.subscribe();
			return observable;
		}
	};
开发者ID:maier49,项目名称:store,代码行数:56,代码来源:createOrderedOperationMixin.ts

示例5: findRouter

export function findRouter(route: Route<Context, Parameters>): Router<Context> {
	while (route.parent) {
		route = route.parent;
	}

	const router = parentMap.get(route);
	if (!router) {
		throw new Error('Cannot generate link for route that is not in the hierarchy');
	}
	else {
		return router;
	}
}
开发者ID:jdonaghue,项目名称:routing,代码行数:13,代码来源:createRouter.ts

示例6: completeStatefulState

/**
 * Internal function to unobserve the state of a `Stateful`.  It emits a `statecomplete` event which can be
 * cancelled.
 *
 * @param stateful The `Stateful` object to unobserve
 */
function completeStatefulState(stateful: Stateful<State>): void {
	const observedState = observedStateMap.get(stateful);
	if (observedState) {
		observedState.handle.destroy();
		const statecomplete = createCancelableEvent({
			type: 'state:completed',
			target: stateful
		});
		stateful.emit(statecomplete);
		if (!statecomplete.defaultPrevented) {
			stateful.destroy();
		}
	}
}
开发者ID:jdonaghue,项目名称:compose,代码行数:20,代码来源:createStateful.ts

示例7: state

}

/**
 * A weak map that contains the stateful's state
 */
const stateWeakMap = new WeakMap<Stateful<State>, State>();

/**
 * Create an instance of a stateful object
 */
const createStateful: StatefulFactory = createEvented
	.mixin({
		className: 'Stateful',
		mixin: {
			get state(this: Stateful<State>): State {
				return stateWeakMap.get(this);
			},

			setState(this: Stateful<State>, value: State): void {
				const observedState = observedStateMap.get(this);
				if (observedState) {
					observedState.observable.patch(value, { id: observedState.id });
				}
				else {
					setStatefulState(this, value);
				}
			},

			observeState(this: Stateful<State>, id: string, observable: ObservableState<State>): Handle {
				let observedState = observedStateMap.get(this);
				if (observedState) {
开发者ID:jdonaghue,项目名称:compose,代码行数:31,代码来源:createStateful.ts

示例8: get

	fetch<U>(query: Query<T, U>): Promise<U[]>;
}

export interface StoreFactory extends ComposeFactory<Store<{}, {}, any>, StoreOptions<{}, {}>> {
	<T extends {}, O extends CrudOptions>(options?: StoreOptions<T, O>): Store<T, O, UpdateResults<T>>;
}

interface BaseStoreState<T, O, U> {
	storage: Storage<T, O>;
}

const instanceStateMap = new WeakMap<Store<{}, {}, any>, BaseStoreState<{}, {}, any>>();

const createStore: StoreFactory = compose<Store<{}, {}, any>, StoreOptions<{}, {}>>({
	get(this: Store<{}, {}, any>, ids: string[] | string): Promise<{}[]> {
		return instanceStateMap.get(this).storage.get(Array.isArray(ids) ? ids : [ ids ]);
	},

	add(this: Store<{}, {}, any>, items: {}[] | {}, options?: CrudOptions) {
		const self = this;
		const storeResultsPromise = instanceStateMap.get(self).storage
			.add(Array.isArray(items) ? items : [ items ], options);
		// TODO refactoring - repetitive logic
		return createStoreObservable(
			new Observable<UpdateResults<{}>>(function subscribe(observer: Observer<UpdateResults<{}>>) {
				storeResultsPromise
					.then(function(results) {
						observer.next(results);
						observer.complete();
					}, function(error) {
						observer.error(error);
开发者ID:maier49,项目名称:store,代码行数:31,代码来源:createStore.ts


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