本文整理汇总了TypeScript中@aurelia/kernel.Registration类的典型用法代码示例。如果您正苦于以下问题:TypeScript Registration类的具体用法?TypeScript Registration怎么用?TypeScript Registration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Registration类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: container
public get container(): IContainer {
if (this._container === null) {
this._container = BasicConfiguration.createContainer();
Registration.instance(IDOM, this.dom).register(this._container);
Registration.instance(HTMLTestContext, this).register(this._container);
}
return this._container;
}
示例2: registerAttribute
export function registerAttribute(this: ICustomAttributeType, container: IContainer): void {
const description = this.description;
const resourceKey = this.kind.keyFrom(description.name);
const aliases = description.aliases;
container.register(Registration.transient(resourceKey, this));
for (let i = 0, ii = aliases.length; i < ii; ++i) {
const aliasKey = this.kind.keyFrom(aliases[i]);
container.register(Registration.alias(resourceKey, aliasKey));
}
}
示例3: setup
function setup() {
const ctx = TestContext.createHTMLTestContext();
const { dom, container } = ctx;
IExpressionParserRegistration.register(container);
const renderable: IRenderable = { $bindingHead: null, $bindingTail: null, $componentHead: null, $componentTail: null, $context: null, $nodes: null, $scope: null };
container.register(Registration.instance(IRenderable, renderable));
const wrapper = ctx.createElementFromMarkup('<div><au-target class="au"></au-target> </div>');
dom.appendChild(ctx.doc.body, wrapper);
const target = wrapper.firstElementChild as HTMLElement;
const placeholder = target.nextSibling as HTMLElement;
const renderingEngine = container.get(IRenderingEngine);
const sut = container.get(IRenderer);
const renderContext: IRenderContext = {
get(key) {
return key === IRenderer ? sut : { $hydrate: spy(), key } as any;
},
beginComponentOperation() {
return {
dispose: spy()
} as any;
},
createChild: PLATFORM.noop as any,
render: PLATFORM.noop,
has: PLATFORM.noop as any,
getAll: PLATFORM.noop as any
};
spy(renderContext, 'get');
spy(renderContext, 'beginComponentOperation');
return { ctx, sut, dom, renderable, target, placeholder, wrapper, renderContext, renderingEngine };
}
示例4: registerComponent
export function registerComponent(container, ...components) {
for (const component of components) {
const name = component.description ? component.description.name : component.name;
container.register(component);
Registration.alias(CustomElementResource.keyFrom(name), component).register(container);
}
}
示例5: constructor
constructor(container: IContainer = DI.createContainer()) {
this.container = container;
this.components = [];
this.startTasks = [];
this.stopTasks = [];
this.isStarted = false;
this._root = null;
Registration
.instance(Aurelia, this)
.register(container, Aurelia);
}
示例6: InstanceProvider
export function hydrateCustomAttribute<T extends ICustomAttributeType>(
Type: T,
options: IAttributeTestOptions = {}
) : ICustomAttributeCreation<T> {
const AttributeType: ICustomAttributeType<AuNode> = Type as any;
const container = options.container || AuDOMConfiguration.createContainer();
const dom = container.get(IDOM);
if (options.lifecycle) {
Registration.instance(ILifecycle, options.lifecycle).register(container, ILifecycle);
}
const lifecycle = container.get(ILifecycle) as Lifecycle;
let location: IRenderLocation<AuNode> & AuNode = null;
container.register(AttributeType);
if (AttributeType.description.isTemplateController) {
const loc = AuNode.createRenderLocation();
AuNode.createHost().appendChild(loc.$start).appendChild(loc);
container.register(
Registration.instance(
IRenderLocation,
location = (options.target as typeof loc) || loc
),
Registration.singleton(IViewFactory, FakeViewFactory)
);
} else {
const hostProvider = new InstanceProvider();
hostProvider.prepare(options.target || AuNode.createHost());
dom.registerElementResolver(container, hostProvider);
}
const attribute = container.get<InstanceType<T> & ICustomAttribute<AuNode>>(
CustomAttributeResource.keyFrom(AttributeType.description.name)
);
attribute.$hydrate(LF.none, container);
return { attribute: attribute as Overwrite<InstanceType<T>, ICustomAttribute<AuNode>>, location, lifecycle };
}
示例7: app
public app(config: ISinglePageApp): this {
const host = config.host as INode & {$au?: Aurelia | null};
const domInitializer = this.container.get(IDOMInitializer);
domInitializer.initialize(config);
Registration.instance(INode, host).register(this.container);
const startFlags = LifecycleFlags.fromStartTask | config.strategy;
const stopFlags = LifecycleFlags.fromStopTask | config.strategy;
let component: ICustomElement;
const componentOrType = config.component as ICustomElement | ICustomElementType;
if (CustomElementResource.isType(componentOrType as ICustomElementType)) {
this.container.register(componentOrType as ICustomElementType);
component = this.container.get<ICustomElement>(CustomElementResource.keyFrom((componentOrType as ICustomElementType).description.name));
} else {
component = componentOrType as ICustomElement;
}
component = ProxyObserver.getRawIfProxy(component);
const startTask = () => {
host.$au = this;
if (!this.components.includes(component)) {
this._root = component;
this.components.push(component);
component.$hydrate(startFlags, this.container as ExposedContext, host);
}
component.$bind(startFlags | LifecycleFlags.fromBind, null);
component.$attach(startFlags | LifecycleFlags.fromAttach);
};
this.startTasks.push(startTask);
this.stopTasks.push(() => {
component.$detach(stopFlags | LifecycleFlags.fromDetach);
component.$unbind(stopFlags | LifecycleFlags.fromUnbind);
host.$au = null;
});
if (this.isStarted) {
startTask();
}
return this;
}
示例8: createObserverLocator
export function createObserverLocator(containerOrLifecycle?: IContainer | ILifecycle): IObserverLocator {
let lifecycle: ILifecycle;
if (containerOrLifecycle === undefined) {
lifecycle = new Lifecycle();
} else if ('get' in containerOrLifecycle) {
lifecycle = containerOrLifecycle.get(ILifecycle);
}
const dummyLocator: any = {
handles(): boolean {
return false;
}
};
const observerLocator = new ObserverLocator(lifecycle, null, dummyLocator, dummyLocator);
if (containerOrLifecycle !== undefined && 'get' in containerOrLifecycle) {
Registration.instance(IObserverLocator, observerLocator).register(containerOrLifecycle, IObserverLocator);
}
return observerLocator;
}
示例9: setup
function setup() {
const container = AuDOMConfiguration.createContainer();
IExpressionParserRegistration.register(container as any);
const dom = container.get(IDOM);
const renderable: IRenderable = {
$bindingHead: null,
$bindingTail: null,
$componentHead: null,
$componentTail: null,
$context: null,
$nodes: null,
$scope: null
};
container.register(Registration.instance(IRenderable, renderable));
const target = AuNode.createMarker();
const renderingEngine = container.get(IRenderingEngine);
const sut = container.get(IRenderer);
const renderContext: IRenderContext = {
get(key) {
return key === IRenderer ? sut : { $hydrate: spy(), key } as any;
},
beginComponentOperation() {
return {
dispose: spy()
} as any;
},
createChild: PLATFORM.noop as any,
render: PLATFORM.noop,
has: PLATFORM.noop as any,
getAll: PLATFORM.noop as any
};
spy(renderContext, 'get');
spy(renderContext, 'beginComponentOperation');
return { sut, renderable, dom, target, renderContext, renderingEngine };
}
示例10: registerElement
export function registerElement(this: ICustomElementType, container: IContainer): void {
const resourceKey = this.kind.keyFrom(this.description.name);
container.register(Registration.transient(resourceKey, this));
}