本文整理匯總了TypeScript中dojo-compose/compose.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: compose
* Create a new MemoryHistory instance.
* @param options Options to use during creation. If not specified the instance sets
* the current value to an empty string.
*/
(options?: MemoryHistoryOptions): MemoryHistory;
}
const createMemoryHistory: MemoryHistoryFactory = compose({
get current () {
return this._current;
},
set (path: string) {
this._current = path;
this.emit({
type: 'change',
value: path
});
},
replace (path: string) {
this.set(path);
}
}).mixin({
mixin: createEvented,
initialize(instance: MemoryHistory, { path }: MemoryHistoryOptions = { path: '' }) {
instance._current = path;
}
});
export default createMemoryHistory;
示例2: getChildrenNodes
import { List } from 'immutable/immutable';
import compose, { ComposeFactory } from 'dojo-compose/compose';
import { Child } from './createParentMixin';
export interface RenderableChildrenOptions {}
export interface RenderableChildrenMixin {
/**
* Return an array of VNodes/strings the represent the rendered results of the children of this instance
*/
getChildrenNodes(): (VNode | string)[];
}
export interface RenderableChildrenFactory extends ComposeFactory<RenderableChildrenMixin, RenderableChildrenOptions> {}
const createRenderableChildrenMixin: RenderableChildrenFactory = compose({
getChildrenNodes(): (VNode | string)[] {
/* When this gets mixed in, if we had the children as part of the interface, we would end up overwritting what is
* likely a get accessor for the children, so to protect ourselves, we won't have it part of the interface */
const renderableChildren: RenderableChildrenMixin & {
children: List<Child>;
} = this;
const results: (VNode | string)[] = [];
/* Converting immutable lists toArray() is expensive */
renderableChildren.children && renderableChildren.children.forEach((child) => results.push(child.render()));
return results;
}
});
export default createRenderableChildrenMixin;
示例3: compose
//.........這裏部分代碼省略.........
destroyed = true;
registryHandle.destroy();
if (instanceHandle) {
instanceHandle.destroy();
}
}
};
},
registerWidget(id: Identifier, widget: WidgetLike): Handle {
const app: App = this;
const promise = Promise.resolve(widget);
const instanceHandle = app._instanceRegistry.addWidget(widget, id);
const registryHandle = widgets.get(app).register(id, () => promise);
return {
destroy() {
this.destroy = noop;
registryHandle.destroy();
instanceHandle.destroy();
}
};
},
registerWidgetFactory(id: Identifier, factory: WidgetFactory): Handle {
const app: App = this;
let destroyed = false;
let instanceHandle: Handle;
let registryHandle = widgets.get(app).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.
const { registryProvider, defaultStore } = app;
interface Options {
id: string;
registryProvider: RegistryProvider;
stateFrom?: StoreLike;
}
const options: Options = { id, registryProvider };
if (defaultStore) {
options.stateFrom = defaultStore;
}
return factory(options);
}).then((widget) => {
if (!destroyed) {
instanceHandle = app._instanceRegistry.addWidget(widget, id);
}
return widget;
});
// Replace the registered factory to ensure next time this widget is needed, the same widget is returned.
registryHandle.destroy();
registryHandle = widgets.get(app).register(id, () => promise);
return promise;
});
return {
destroy() {
this.destroy = noop;
destroyed = true;
registryHandle.destroy();
if (instanceHandle) {
instanceHandle.destroy();
}
}
示例4: isRenderable
}
export type Renderable = Destroyable & RenderableMixin;
export interface RenderableFactory extends ComposeFactory<Renderable, RenderableOptions> { }
export function isRenderable(value: any): value is Renderable {
return value && typeof value.render === 'function';
}
const createRenderable: RenderableFactory = compose<RenderableMixin, RenderableOptions>({
render() {
const renderable: Renderable = this;
return h(renderable.tagName);
},
tagName: 'div'
}, (instance, options) => {
if (options) {
const { tagName, render, parent } = options;
instance.tagName = tagName || instance.tagName;
instance.render = render || instance.render;
if (parent) {
parent.append(instance);
}
}
})
.mixin(createDestroyable);
export default createRenderable;
示例5: 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;
示例6: compose
const createFormMixin: FormMixinFactory = compose({
get value(): string {
const formfield: FormFieldMixin<any, FormFieldMixinState<any>> = this;
return valueToString(formfield.state.value);
},
set value(value: string) {
const formfield: FormFieldMixin<any, FormFieldMixinState<any>> = this;
if (value !== formfield.state.value) {
const event = assign(createCancelableEvent({
type: 'valuechange',
target: formfield
}), {
oldValue: valueToString(formfield.state.value),
value
});
formfield.emit(event);
if (!event.defaultPrevented) {
formfield.setState({ value: stringToValue(event.value) });
}
}
}
}, (instance: FormField<any>, options: FormFieldMixinOptions<any, FormFieldMixinState<any>>) => {
if (options) {
const { type } = options;
if (type) {
instance.type = type;
}
}
})
.mixin({
示例7: state
const createStateful: StatefulFactory = compose({
get state(): any {
return stateWeakMap.get(this);
},
setState(value: State): void {
const stateful: Stateful<any> = this;
const observedState = observedStateMap.get(stateful);
if (observedState) {
observedState.observable.patch(value, { id: observedState.id });
}
else {
setStatefulState(stateful, value);
}
},
observeState(id: string, observable: ObservableState<State>): Handle {
const stateful: Stateful<any> = this;
let observedState = observedStateMap.get(stateful);
if (observedState) {
if (observedState.id === id && observedState.observable === observable) {
return observedState.handle;
}
throw new Error('Already observing state.');
}
observedState = {
id,
observable,
subscription: observable.observe(id).subscribe((item: State) => {
setStatefulState(stateful, item);
}, (err) => { /* error handler */
stateful.emit({
type: 'error',
target: stateful,
error: err
});
unobserve(stateful);
}, () => { /* completed handler */
unobserve(stateful);
}),
handle: {
destroy() {
const observedState = observedStateMap.get(stateful);
if (observedState) {
observedState.subscription.unsubscribe();
observedStateMap.delete(stateful);
}
}
}
};
observedStateMap.set(stateful, observedState);
return observedState.handle;
}
}, (instance: any, options: StatefulOptions<State>) => {
const state = {};
stateWeakMap.set(instance, state);
if (options) {
if (options.state) {
instance.setState(options.state);
}
if (options.id && options.stateFrom) {
instance.own(instance.observeState(options.id, options.stateFrom));
}
else if (options.id || options.stateFrom) {
throw new TypeError('Factory requires options "id" and "stateFrom" to be supplied together.');
}
}
})
示例8: isTask
/**
* 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);
if (configureFn) {
return configureFn.call(this, configuration);
}
}
})
.mixin({
mixin: createStateful,
initialize(instance: AnyAction, { do: doFn, enabled = true, configure }: ActionOptions<any, ActionState>) {
示例9: current
const createStateHistory: StateHistoryFactory = compose({
get current () {
return this._current;
},
set (path: string) {
this._current = path;
this._history.pushState({}, '', path);
this.emit({
type: 'change',
value: path
});
},
replace (path: string) {
this._current = path;
this._history.replaceState({}, '', path);
this.emit({
type: 'change',
value: path
});
},
_onPopstate (path: string) {
// Ignore popstate for the current path. Guards against browsers firing
// popstate on page load, see
// <https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate>.
if (path !== this._current) {
this._current = path;
this.emit({
type: 'change',
value: path
});
}
}
}).mixin({
示例10: factory
const createApp = compose({
registerAction(id: Identifier, action: ActionLike): Handle {
let registryHandle = actions.get(this).register(id, () => {
const promise = new Promise<void>((resolve) => {
resolve(action.configure(this._registry));
}).then(() => action);
registryHandle.destroy();
registryHandle = actions.get(this).register(id, () => promise);
return promise;
});
return {
destroy() {
this.destroy = noop;
registryHandle.destroy();
}
};
},
registerActionFactory(id: Identifier, factory: ActionFactory): Handle {
let registryHandle = actions.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(this._registry);
});
// Replace the registered factory to ensure next time this action is needed, the same action is returned.
registryHandle.destroy();
registryHandle = actions.get(this).register(id, () => promise);
return promise.then((action) => {
return Promise.resolve(action.configure(this._registry)).then(() => action);
});
});
return {
destroy() {
this.destroy = noop;
registryHandle.destroy();
}
};
},
registerCustomElementFactory(name: string, factory: WidgetFactory): Handle {
if (!isValidName(name)) {
throw new SyntaxError(`'${name}' is not a valid custom element name'`);
}
// Wrap the factory since the registry cannot store frozen factories, and dojo-compose creates
// frozen factoriesâŚ
const wrapped = (options: Object) => factory(options);
// Note that each custom element requires a new widget, so there's no need to replace the
// registered factory.
const registryHandle = customElements.get(this).register(normalizeName(name), wrapped);
return {
destroy() {
this.destroy = noop;
registryHandle.destroy();
}
};
},
registerStore(id: Identifier, store: StoreLike): Handle {
const promise = Promise.resolve(store);
return stores.get(this).register(id, () => promise);
},
registerStoreFactory(id: Identifier, factory: StoreFactory): Handle {
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;
});
return {
destroy() {
this.destroy = noop;
registryHandle.destroy();
}
};
},
registerWidget(id: Identifier, widget: WidgetLike): Handle {
const promise = Promise.resolve(widget);
return widgets.get(this).register(id, () => promise);
},
registerWidgetFactory(id: Identifier, factory: WidgetFactory): Handle {
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
//.........這裏部分代碼省略.........