本文整理匯總了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);
});
示例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;
}
示例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;
}
示例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);
});
示例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();
示例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(() => {
示例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: [
示例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();
示例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(() => {
示例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
});
}