本文整理汇总了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);
});
示例2: spy
const request = spy((path: string, data: any) => {
if (requestHandler) {
return requestHandler(path, data);
}
const result = requestData && requestData[path];
return Task.resolve(result);
});
示例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());
}
示例4: constructor
constructor(options: HttpChannelOptions) {
super(options);
this._sequence = 1;
this._maxPostSize = options.maxPostSize || 100000;
this._messageBuffer = [];
this._lastRequest = Task.resolve();
}
示例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();
}
示例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);
}
示例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');
});
}
}
};
});
示例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);
示例10: resolve
resolve({ json: () => Task.resolve(responses) });