當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Registry.defineInjector方法代碼示例

本文整理匯總了TypeScript中@dojo/widget-core/Registry.Registry.defineInjector方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Registry.defineInjector方法的具體用法?TypeScript Registry.defineInjector怎麽用?TypeScript Registry.defineInjector使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@dojo/widget-core/Registry.Registry的用法示例。


在下文中一共展示了Registry.defineInjector方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

		it('Should only invalidate when the path passed is changed', () => {
			@storeInject<State>({
				name: 'state',
				paths: [['foo']],
				getProperties: (store) => {
					return {
						foo: store.get(store.path('foo'))
					};
				}
			})
			class TestWidget extends WidgetBase<any> {}
			const widget = new TestWidget();
			registry.defineInjector('state', () => () => store);
			widget.__setCoreProperties__({ bind: widget, baseRegistry: registry });
			widget.__setProperties__({});
			const invalidateSpy = spy(widget, 'invalidate');
			assert.strictEqual(widget.properties.foo, undefined);
			fooProcess(store)({});
			assert.isTrue(invalidateSpy.calledOnce);
			widget.__setProperties__({});
			assert.isTrue(invalidateSpy.calledTwice);
			assert.strictEqual(widget.properties.foo, 'foo');
			barProcess(store)({});
			assert.isTrue(invalidateSpy.calledTwice);
		});
開發者ID:dojo,項目名稱:stores,代碼行數:25,代碼來源:StoreInjector.ts

示例2: registerRouterInjector

export function registerRouterInjector(
	config: RouteConfig[],
	registry: Registry,
	options: RouterInjectorOptions = {}
): Router {
	const { key = 'router', ...routerOptions } = options;

	if (registry.hasInjector(key)) {
		throw new Error('Router has already been defined');
	}
	const router = new Router(config, routerOptions);
	registry.defineInjector(key, (invalidator: () => void) => {
		router.on('navstart', () => invalidator());
		return () => router;
	});
	return router;
}
開發者ID:dojo,項目名稱:routing,代碼行數:17,代碼來源:RouterInjector.ts

示例3: registerRouterInjector

export function registerRouterInjector(
	config: RouteConfig[],
	registry: Registry,
	options: RouterInjectorOptions = {}
): Router {
	const { key = 'router', ...routerOptions } = options;

	if (registry.hasInjector(key)) {
		throw new Error('Router has already been defined');
	}
	const router = new Router(config, routerOptions);
	const injector = new Injector(router);
	router.on('navstart', () => {
		injector.emit({ type: 'invalidate' });
	});
	registry.defineInjector(key, injector);
	return router;
}
開發者ID:mwistrand,項目名稱:routing,代碼行數:18,代碼來源:RouterInjector.ts

示例4: it

		it('Should always render a container', () => {
			let invalidateCounter = 0;
			class Foo extends WidgetBase {}
			class FooContainer extends StoreContainer(Foo, 'state', { getProperties: () => {} }) {
				invalidate() {
					invalidateCounter++;
				}
			}
			const fooContainer = new FooContainer();
			registry.defineInjector('state', new StoreInjector(store));
			fooContainer.__setProperties__({});
			assert.strictEqual(invalidateCounter, 1);
			fooContainer.__setProperties__({});
			assert.strictEqual(invalidateCounter, 2);
			fooContainer.__setProperties__({});
			assert.strictEqual(invalidateCounter, 3);
			fooContainer.__setProperties__({});
			assert.strictEqual(invalidateCounter, 4);
		});
開發者ID:mwistrand,項目名稱:stores,代碼行數:19,代碼來源:StoreInjector.ts

示例5: Registry

import { Registry } from '@dojo/widget-core/Registry';

import { TodoAppContainer } from './containers/TodoAppContainer';
import { createStore } from 'redux';
import { todoReducer } from './reducers';

const defaultState = {
	todos: [],
	currentTodo: '',
	activeCount: 0,
	completedCount: 0
};

const registry = new Registry();
const store = createStore(todoReducer, defaultState, global.__REDUX_DEVTOOLS_EXTENSION__ && global.__REDUX_DEVTOOLS_EXTENSION__());
registry.defineInjector('application-state', new ReduxInjector(store));

const config = [
	{
		path: 'filter/{filter}',
		outlet: 'filter',
		defaultParams: {
			filter: 'all'
		},
		defaultRoute: true
	}
];

const router = registerRouterInjector(config, registry);
const Projector = ProjectorMixin(TodoAppContainer);
const projector = new Projector();
開發者ID:agubler,項目名稱:examples,代碼行數:31,代碼來源:main.ts

示例6: Router

const router = new Router(
	[
		{
			path: 'foo',
			outlet: 'foo'
		},
		{
			path: 'foo/{foo}',
			outlet: 'foo2'
		}
	],
	{ HistoryManager: MemoryHistory }
);

registry.defineInjector('router', new Injector(router));

let routerSetPathSpy: SinonSpy;

function createMockEvent(isRightClick: boolean = false) {
	return {
		defaultPrevented: false,
		preventDefault() {
			this.defaultPrevented = true;
		},
		button: isRightClick ? undefined : 0
	};
}

describe('Link', () => {
	beforeEach(() => {
開發者ID:mwistrand,項目名稱:routing,代碼行數:30,代碼來源:Link.ts

示例7: Registry

import { ProjectorMixin } from '@dojo/widget-core/mixins/Projector';
import { registerRouterInjector } from '@dojo/routing/RouterInjector';
import { Registry } from '@dojo/widget-core/Registry';

import { TodoAppContainer } from './containers/TodoAppContainer';
import { registerThemeInjector } from '@dojo/widget-core/mixins/Themed';
import { initialStateProcess } from './todoProcesses';
import StoreInjector from './StoreInjector';
import Injector from '@dojo/widget-core/Injector';

const registry = new Registry();
const store = new Store();
const themeContext = registerThemeInjector(undefined, registry);

initialStateProcess(store)({});
registry.defineInjector('state', new StoreInjector(store));
registry.defineInjector('theme-context', new Injector(themeContext));

const Projector = ProjectorMixin(TodoAppContainer);
const projector = new Projector();

const config = [
	{
		path: 'view/{view}?{filter}',
		outlet: 'view',
		defaultParams: {
			filter: 'all',
			view: 'list'
		},
		defaultRoute: true,
		children: [
開發者ID:dylans,項目名稱:examples,代碼行數:31,代碼來源:main.ts

示例8: getTagsProcess

getTagsProcess(store)({});
if (session) {
	setSessionProcess(store)({ session: JSON.parse(session) });
}

router.on('nav', ({ outlet, context }: any) => {
	changeRouteProcess(store)({ outlet, context });
});

function onRouteChange() {
	const outlet = store.get(store.path('routing', 'outlet'));
	const params = store.get(store.path('routing', 'params'));
	if (outlet) {
		const link = router.link(outlet, params);
		if (link !== undefined) {
			router.setPath(link);
		}
	}
}

store.onChange(store.path('routing', 'outlet'), onRouteChange);
store.onChange(store.path('routing', 'params'), onRouteChange);

registry.defineInjector('state', new StoreInjector(store));

const Projector = ProjectorMixin(App);
const projector = new Projector();
projector.setProperties({ registry });

projector.append();
開發者ID:dylans,項目名稱:examples,代碼行數:30,代碼來源:main.ts

示例9: Router

const router = new Router(
	[
		{
			path: 'foo',
			outlet: 'foo'
		},
		{
			path: 'foo/{foo}',
			outlet: 'foo2'
		}
	],
	{ HistoryManager: MemoryHistory }
);

registry.defineInjector('router', () => () => router);

let routerSetPathSpy: SinonSpy;

function createMockEvent(isRightClick: boolean = false) {
	return {
		defaultPrevented: false,
		preventDefault() {
			this.defaultPrevented = true;
		},
		button: isRightClick ? undefined : 0
	};
}

describe('Link', () => {
	beforeEach(() => {
開發者ID:dojo,項目名稱:routing,代碼行數:30,代碼來源:Link.ts

示例10: Registry

import { ProjectorMixin } from '@dojo/widget-core/mixins/Projector';
import { registerThemeInjector } from '@dojo/widget-core/mixins/Themed';
import { Registry } from '@dojo/widget-core/Registry';
import Injector from '@dojo/widget-core/Injector';
import App from './App';
import dojo from '@dojo/themes/dojo';

const themes: { [index: string]: any } = {
	dojo,
	vanilla: undefined
};

const registry = new Registry();
const themeContext = registerThemeInjector(dojo, registry);

registry.defineInjector('theme-context', new Injector(themeContext));

let initialAppState = {
	registry,
	themes: Object.keys(themes),
	currentTheme: 'dojo',
	onThemeChange: _onThemechange
}

function _onThemechange(theme: string) {
	themeContext.set(themes[theme]);
	projector.setProperties({
		...initialAppState,
		currentTheme: theme
	});
}
開發者ID:agubler,項目名稱:examples,代碼行數:31,代碼來源:main.ts


注:本文中的@dojo/widget-core/Registry.Registry.defineInjector方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。