本文整理汇总了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;