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


TypeScript compose.default函数代码示例

本文整理汇总了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;
开发者ID:matt-gadd,项目名称:routing,代码行数:31,代码来源:createMemoryHistory.ts

示例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;
开发者ID:novemberborn,项目名称:widgets,代码行数:30,代码来源:createRenderableChildrenMixin.ts

示例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();
				}
			}
开发者ID:datafordevelopment,项目名称:dojo-frame,代码行数:67,代码来源:createApp.ts

示例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;
开发者ID:novemberborn,项目名称:widgets,代码行数:30,代码来源:createRenderable.ts

示例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;
开发者ID:matt-gadd,项目名称:dojo2-todo-mvc,代码行数:29,代码来源:createTodoRegistry.ts

示例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({
开发者ID:novemberborn,项目名称:widgets,代码行数:31,代码来源:createFormFieldMixin.ts

示例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.');
			}
		}
	})
开发者ID:benpope82,项目名称:widgets,代码行数:68,代码来源:createStateful.ts

示例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>) {
开发者ID:jdonaghue,项目名称:actions,代码行数:32,代码来源:createAction.ts

示例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({
开发者ID:matt-gadd,项目名称:routing,代码行数:36,代码来源:createStateHistory.ts

示例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
//.........这里部分代码省略.........
开发者ID:digideskio,项目名称:app,代码行数:101,代码来源:createApp.ts


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