本文整理匯總了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;
});
示例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;
});
示例3:
return promise.then((action) => {
return Promise.resolve(action.configure(this._registry)).then(() => action);
});
示例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;
示例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() {
示例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(() => {
示例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;
示例8: function
const noop = function() { return Promise.resolve(false); };
示例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;