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


TypeScript Task.resolve函数代码示例

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


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

示例1: spy

	const request = spy((path: string) => {
		if (requester) {
			return requester(path);
		}
		const data = requestData && requestData[path];
		return Task.resolve(data);
	});
开发者ID:jason0x43,项目名称:intern,代码行数:7,代码来源:Http.ts

示例2: spy

	const request = spy((path: string, data: any) => {
		if (requestHandler) {
			return requestHandler(path, data);
		}
		const result = requestData && requestData[path];
		return Task.resolve(result);
	});
开发者ID:devpaul,项目名称:intern,代码行数:7,代码来源:Http.ts

示例3: loadScript

	/**
	 * Load a script or scripts via script injection.
	 *
	 * @param script a path to a script
	 */
	loadScript(script: string | string[]) {
		if (script == null) {
			return Task.resolve();
		}

		if (typeof script === 'string') {
			script = [script];
		}

		return script.reduce((previous, script) => {
			if (script[0] !== '/') {
				script = `${this.config.basePath}${script}`;
			}
			return previous.then(() => injectScript(script));
		}, Task.resolve());
	}
开发者ID:bryanforbes,项目名称:intern,代码行数:21,代码来源:Browser.ts

示例4: constructor

	constructor(options: HttpChannelOptions) {
		super(options);
		this._sequence = 1;
		this._maxPostSize = options.maxPostSize || 100000;
		this._messageBuffer = [];
		this._lastRequest = Task.resolve();
	}
开发者ID:gitgrimbo,项目名称:intern,代码行数:7,代码来源:Http.ts

示例5: loadScript

export function loadScript(script: string | string[]) {
	if (!Array.isArray(script)) {
		script = [script];
	}

	script.forEach(script => {
		script = resolve(script);
		// Delete the module cache entry for the script to ensure it will be loaded and executed again.
		delete require.cache[script];
		require(script);
	});

	return Task.resolve();
}
开发者ID:bryanforbes,项目名称:intern,代码行数:14,代码来源:util.ts

示例6: dispatch

	dispatch(context: Context, path: string): Task<DispatchResult> {
		// Reset, any further calls can't have come from start(). This is necessary since the navstart listeners
		// may call dispatch() themselves.
		let dispatchFromStart = this._dispatchFromStart;
		this._dispatchFromStart = false;

		let canceled = false;
		const cancel = () => {
			canceled = true;
		};

		const deferrals: Promise<void>[] = [];

		this.emit<NavigationStartEvent>({
			cancel,
			defer () {
				const { cancel, promise, resume } = createDeferral();
				deferrals.push(promise);
				return { cancel, resume };
			},
			path,
			target: this,
			type: 'navstart'
		});

		// Synchronous cancelation.
		if (canceled) {
			return Task.resolve({ success: false });
		}

		const { searchParams, segments, trailingSlash } = parsePath(path);
		return new Task<DispatchResult>((resolve, reject) => {
			// *Always* start dispatching in a future turn, even if there were no deferrals.
			Promise.all(deferrals).then<DispatchResult>(
				() => {
					// The cancel() function used in the NavigationStartEvent is reused as the Task canceler.
					// Strictly speaking any navstart listener can cancel the dispatch asynchronously, as long as it
					// manages to do so before this turn.
					if (canceled) {
						return { success: false };
					}

					let redirect: undefined | string;
					const dispatched = this._routes.some((route) => {
						const result = route.select(context, segments, trailingSlash, searchParams);

						if (typeof result === 'string') {
							redirect = result;
							return true;
						}
						if (result.length === 0) {
							return false;
						}

						// Update the selected routes after selecting new routes, but before invoking the handlers.
						// This means the original value is available to guard() and params() functions, and the
						// new value when the newly selected routes are executed.
						//
						// Reset selected routes if not dispatched from start().
						this._currentSelection = dispatchFromStart ? result : [];

						for (const { handler, params } of result) {
							catchRejection(this, context, path, handler({ context, params }));
						}

						return true;
					});

					// Reset the selected routes if the dispatch was unsuccessful, or if a redirect was requested.
					if (!dispatched || redirect !== undefined) {
						this._currentSelection = [];
					}

					if (!dispatched && this._fallback) {
						catchRejection(this, context, path, this._fallback({ context, params: {} }));
						return { success: false };
					}

					const result: DispatchResult = { success: dispatched };
					if (redirect !== undefined) {
						result.redirect = redirect;
					}
					return result;
				},
				// When deferrals are canceled their corresponding promise is rejected. Ensure the task resolves
				// with `false` instead of being rejected too.
				() => {
					return { success: false };
				}
			).then(resolve, (error) => {
				reportError(this, context, path, error);
				reject(error);
			});
		}, cancel);
	}
开发者ID:dylans,项目名称:routing,代码行数:95,代码来源:Router.ts

示例7: registerSuite

registerSuite('lib/channels/Http', function() {
	const request = spy((path: string) => {
		if (requester) {
			return requester(path);
		}
		const data = requestData && requestData[path];
		return Task.resolve(data);
	});

	let requestData: { [name: string]: string };
	let removeMocks: () => void;
	let requester: ((path: string) => Task<void>) | undefined;

	return {
		before() {
			return mockRequire(require, 'src/lib/channels/Http', {
				'@dojo/core/request/providers/xhr': { default: request }
			}).then(handle => {
				removeMocks = handle.remove;
				Http = handle.module.default;
			});
		},

		after() {
			removeMocks();
		},

		beforeEach() {
			requester = undefined;
		},

		tests: {
			'#sendMessage'() {
				const http = new Http({ sessionId: 'foo', url: 'bar' });
				const requests: (() => void)[] = [];

				requester = () => {
					return new Task<void>(resolve => {
						requests.push(resolve);
					});
				};

				http.sendMessage('remoteStatus', 'foo');
				http.sendMessage('remoteStatus', 'bar');
				const send3 = http.sendMessage('remoteStatus', 'baz');

				// Run first request check in a task resolve since first
				// sendData call waits for a Task resolution
				return Task.resolve()
					.then(() => {
						assert.lengthOf(requests, 1);
						requests[0]();
						return send3;
					})
					.then(() => {
						assert.equal(request.callCount, 1);
						const messageStrings = JSON.parse(
							request.getCall(0).args[1].body
						);
						assert.lengthOf(messageStrings, 3);
						const messages = messageStrings.map(JSON.parse);
						assert.propertyVal(messages[0], 'data', 'foo');
						assert.propertyVal(messages[1], 'data', 'bar');
						assert.propertyVal(messages[2], 'data', 'baz');
					});
			}
		}
	};
});
开发者ID:jason0x43,项目名称:intern,代码行数:69,代码来源:Http.ts

示例8: do

const doFunctions = new WeakMap<AnyAction, DoFunction<any>>();

/**
 * A weak map of `configure` methods
 */
const configureFunctions = new WeakMap<AnyAction, (configuration: Object) => Promise<void> | void>();

/**
 * A factory which creates instances of Action
 */
const createAction: ActionFactory = compose<ActionMixin<any, DoOptions<any, TargettedEventObject<any>>>, ActionOptions<any, ActionState>>({
		do(this: AnyAction, options?: DoOptions<any, TargettedEventObject<any>>): Task<any> {
			const doFn = doFunctions.get(this);
			if (doFn && this.state.enabled) {
				const result = doFn.call(this, options);
				return isTask(result) ? result : Task.resolve(result);
			}
			return Task.resolve();
		},
		enable(this: AnyAction): void {
			if (!this.state.enabled) {
				this.setState({ enabled: true });
			}
		},
		disable(this: AnyAction): void {
			if (this.state.enabled) {
				this.setState({ enabled: false });
			}
		},
		configure(this: AnyAction, configuration: Object): Promise<void> | void {
			const configureFn = configureFunctions.get(this);
开发者ID:dylans,项目名称:actions,代码行数:31,代码来源:createAction.ts

示例9: run

		run() {
			return Task.resolve();
		}
开发者ID:jason0x43,项目名称:intern,代码行数:3,代码来源:intern.ts

示例10: resolve

							resolve({ json: () => Task.resolve(responses) });
开发者ID:devpaul,项目名称:intern,代码行数:1,代码来源:Http.ts


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