當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Promise.resolve函數代碼示例

本文整理匯總了TypeScript中dojo-core/Promise.resolve函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript resolve函數的具體用法?TypeScript resolve怎麽用?TypeScript resolve使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了resolve函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: factory

		let registryHandle = widgets.get(this).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.
				return factory();
			});
			registryHandle.destroy();
			registryHandle = widgets.get(this).register(id, () => promise);
			return promise;
		});
開發者ID:dylans,項目名稱:app,代碼行數:10,代碼來源:createApp.ts

示例2: factory

		let registryHandle = stores.get(this).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.
				return factory();
			});
			// Replace the registered factory to ensure next time this store is needed, the same store is returned.
			registryHandle.destroy();
			registryHandle = stores.get(this).register(id, () => promise);
			return promise;
		});
開發者ID:digideskio,項目名稱:app,代碼行數:11,代碼來源:createApp.ts

示例3:

			return promise.then((action) => {
				return Promise.resolve(action.configure(this._registry)).then(() => action);
			});
開發者ID:digideskio,項目名稱:app,代碼行數:3,代碼來源:createApp.ts

示例4: close

	close(): Promise<boolean>;

	on(type: 'close', listener: EventedListener<CloseEvent>): Handle;
	on(type: string, listener: EventedListener<TargettedEventObject>): Handle;
}

export interface CloseableMixinFactory extends ComposeFactory<Closeable<CloseableState>, StatefulOptions<CloseableState>> { }

const createCloseableMixin: CloseableMixinFactory = createStateful
	.mixin({
		mixin: {
			close(): Promise<boolean> {
				const closeable: Closeable<CloseableState> = this;
				if (closeable.state.closeable) {
					let prevented = false;
					closeable.emit({
						type: 'close',
						target: closeable,
						preventDefault() {
							prevented = true;
						}
					});
					return prevented ? Promise.resolve(false) : closeable.destroy();
				}
				return Promise.resolve(false);
			}
		}
	});

export default createCloseableMixin;
開發者ID:danice,項目名稱:widgets,代碼行數:30,代碼來源:createCloseableMixin.ts

示例5: children

	'option.parent'() {
		let count = 0;
		const parent: ParentMixin<Child> = {
			get children(): List<Child> {
				return;
			},
			append(child: any) {
				assert.strictEqual(child.tagName, 'div');
				child.parent = this;
				count++;
				return { destroy() { } };
			},
			clear() { },
			insert() { return { destroy() { } }; },
			own() { return { destroy() { } }; },
			destroy() { return Promise.resolve(true); },
			emit() { },
			on(): Handle { return { destroy () { } }; }
		};
		const renderable = createRenderable({
			render() {
				return h('h1', [ 'Greetings' ]);
			},
			parent
		});
		assert.strictEqual(renderable.parent, parent);
		assert.strictEqual(count, 1);
	},
	'isRenderable'() {
		const renderable = createRenderable({
			render() {
開發者ID:novemberborn,項目名稱:widgets,代碼行數:31,代碼來源:createRenderable.ts

示例6: createStateful

		'observeState'() {
			const dfd = this.async();
			const stateful = createStateful();
			const observable = {
				observe(id: string): Observable<Object> {
					assert.strictEqual(id, 'foo');
					return new Observable<Object>(function subscribe(observer: Observer<Object>) {
						setTimeout(() => {
							observer.next({ id: 'foo', foo: 'foo' });
							observer.next({ id: 'foo', foo: 'bar' });
							observer.next({ id: 'foo', foo: 'qat' });
						}, 1);
					});
				},
				patch(partial: any, options?: { id?: string }): Promise<Object> {
					return Promise.resolve(partial);
				}
			};

			let count = 0;
			let handle: Handle;

			stateful.on('statechange', (event) => {
				count++;
				if (count === 1) {
					assert.deepEqual(event.target.state, { id: 'foo', foo: 'foo' });
				}
				else if (count === 2) {
					assert.deepEqual(event.target.state, { id: 'foo', foo: 'bar' });
					handle.destroy();
					setTimeout(() => {
開發者ID:benpope82,項目名稱:widgets,代碼行數:31,代碼來源:createStateful.ts

示例7: compose

const idToWidgetMap = new Map<string, Child>();
const widgetToIdMap = new WeakMap<Child, string>();

interface TodoRegistryOptions {
	widgetStore: MemoryStore<Object>;
}

const todoRegistryFactory = compose({
	get(id: string): Promise<Child> {
		let widget: Child = idToWidgetMap.get(id);
		if (!widget) {
			widget = createTodoItem({id, stateFrom: this.widgetStore});
			widgetToIdMap.set(widget, id);
			idToWidgetMap.set(id, widget);
		}
		return Promise.resolve(widget);
	},
	identify(value: Child): string {
		return widgetToIdMap.get(value);
	}
}, function (todoRegistry: any, options: any) {
	if (options) {
		for (let key in options) {
			todoRegistry[key] = options[key];
		}
	}
});

export default todoRegistryFactory;
開發者ID:matt-gadd,項目名稱:dojo2-todo-mvc,代碼行數:29,代碼來源:createTodoRegistry.ts

示例8: function

const noop = function() { return Promise.resolve(false); };
開發者ID:benpope82,項目名稱:widgets,代碼行數:1,代碼來源:createDestroyable.ts

示例9: close

export interface Closeable {
	/**
	 * Attempt to close the widget
	 */
	close(): Promise<boolean>;

	on(type: 'close', listener: EventedListener<CloseEvent>): Handle;
	on(type: string, listener: EventedListener<TargettedEventObject>): Handle;
}

export type CloseableMixin<S extends CloseableState> = Stateful<S> & Closeable;

export interface CloseableMixinFactory extends ComposeFactory<CloseableMixin<CloseableState>, StatefulOptions<CloseableState>> { }

const createCloseableMixin: CloseableMixinFactory = createStateful
	.mixin({
		mixin: {
			close(): Promise<boolean> {
				const closeable: CloseableMixin<CloseableState> = this;
				if (closeable.state.closeable) {
					const event = createCancelableEvent({ type: 'close', target: closeable });
					closeable.emit(event);
					return event.defaultPrevented ? Promise.resolve(false) : closeable.destroy();
				}
				return Promise.resolve(false);
			}
		}
	});

export default createCloseableMixin;
開發者ID:novemberborn,項目名稱:widgets,代碼行數:30,代碼來源:createCloseableMixin.ts


注:本文中的dojo-core/Promise.resolve函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。