本文整理汇总了TypeScript中@aurelia/kernel.DI类的典型用法代码示例。如果您正苦于以下问题:TypeScript DI类的具体用法?TypeScript DI怎么用?TypeScript DI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DI类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('SelfBindingBehavior', function () {
const container: IContainer = DI.createContainer();
let sut: SelfBindingBehavior;
let binding: Binding;
let originalCallSource: () => void;
beforeEach(function () {
sut = new SelfBindingBehavior();
binding = new Binding(undefined, undefined, undefined, undefined, undefined, container as any);
originalCallSource = binding['callSource'] = function () { return; };
binding['targetEvent'] = 'foo';
sut.bind(undefined, undefined, binding as any);
});
// TODO: test properly (different binding types)
it('bind() should apply the correct behavior', function () {
expect(binding['selfEventCallSource'] === originalCallSource).to.equal(true);
expect(binding['callSource'] === originalCallSource).to.equal(false);
expect(typeof binding['callSource']).to.equal('function');
});
it('unbind() should revert the original behavior', function () {
sut.unbind(undefined, undefined, binding as any);
expect(binding['selfEventCallSource']).to.equal(null);
expect(binding['callSource'] === originalCallSource).to.equal(true);
});
});
示例2: describe
describe('BindingModeBehavior', function () {
const container: IContainer = DI.createContainer();
let sut: OneTimeBindingBehavior;
let binding: Binding;
for (const { Behavior, mode } of tests) {
const initModeArr = [BindingMode.oneTime, BindingMode.toView, BindingMode.fromView, BindingMode.twoWay, BindingMode.default];
for (const initMode of initModeArr) {
describe(Behavior.name, function () {
beforeEach(function () {
sut = new Behavior();
binding = new Binding(undefined, undefined, undefined, initMode, undefined, container as any);
sut.bind(undefined, undefined, binding);
});
it(`bind() should apply bindingMode ${mode}`, function () {
expect(binding.mode).to.equal(mode);
});
it(`unbind() should revert bindingMode ${initMode}`, function () {
sut.unbind(undefined, undefined, binding);
expect(binding.mode).to.equal(initMode);
});
});
}
}
});
示例3: describe
describe('DebounceBindingBehavior', function () {
const container: IContainer = DI.createContainer();
let sut: DebounceBindingBehavior;
let binding: Binding;
let originalFn: (newValue: unknown, previousValue: unknown, flags: LifecycleFlags) => void;
beforeEach(function () {
sut = new DebounceBindingBehavior();
binding = new Binding(undefined, undefined, undefined, undefined, undefined, container);
originalFn = binding.handleChange;
sut.bind(undefined, undefined, binding as any);
});
// TODO: test properly (whether debouncing works etc)
it('bind() should apply the correct behavior', function () {
expect(binding['debouncedMethod'] === originalFn).to.equal(true);
expect(binding['debouncedMethod'].originalName).to.equal('handleChange');
expect(binding.handleChange === originalFn).to.equal(false);
expect(typeof binding.handleChange).to.equal('function');
expect(binding['debounceState']).not.to.equal(null);
expect(typeof binding['debounceState']).to.equal('object');
});
it('unbind() should revert the original behavior', function () {
sut.unbind(undefined, undefined, binding as any);
expect(binding['debouncedMethod']).to.equal(null);
expect(binding.handleChange === originalFn).to.equal(true);
expect(typeof binding.handleChange).to.equal('function');
expect(binding['debounceState']).to.equal(null);
});
});
示例4: it
it(`parse [${defs.map(d => d.pattern)}] -> interpret [${value}] -> match=[${match}]`, function () {
let receivedRawName: string;
let receivedRawValue: string;
let receivedParts: string[];
@attributePattern(...defs)
// @ts-ignore
class ThePattern {}
for (const { pattern } of defs) {
ThePattern.prototype[pattern] = (rawName, rawValue, parts) => {
receivedRawName = rawName;
receivedRawValue = rawValue;
receivedParts = parts;
};
}
const container = DI.createContainer();
container.register(ThePattern as any);
const interpreter = container.get(ISyntaxInterpreter);
const attrPattern = container.get(IAttributePattern);
interpreter.add(attrPattern.$patternDefs);
const result = interpreter.interpret(value);
if (match !== null) {
expect(attrPattern.$patternDefs.map(d => d.pattern).indexOf(result.pattern)).to.be.gte(0);
attrPattern[result.pattern](value, 'foo', result.parts);
expect(receivedRawName).to.equal(value);
expect(receivedRawValue).to.equal('foo');
expect(receivedParts).to.deep.equal(result.parts);
} else {
expect(attrPattern.$patternDefs.map(d => d.pattern)).not.to.contain(result.pattern);
}
expect(result.parts).to.deep.equal(values);
});
示例5: describe
describe('ThrottleBindingBehavior', function () {
const container: IContainer = DI.createContainer();
let sut: ThrottleBindingBehavior;
let binding: Binding;
let originalFn: (value: unknown, flags: LifecycleFlags) => void;
beforeEach(function () {
sut = new ThrottleBindingBehavior();
binding = new Binding(undefined, undefined, undefined, undefined, undefined, container);
originalFn = binding.updateTarget;
sut.bind(undefined, undefined, binding as any);
});
// TODO: test properly (whether throttling works etc)
it('bind() should apply the correct behavior', function () {
expect(binding['throttledMethod'] === originalFn).to.equal(true);
expect(binding['throttledMethod'].originalName).to.equal('updateTarget');
expect(binding.updateTarget === originalFn).to.equal(false);
expect(typeof binding.updateTarget).to.equal('function');
expect(binding['throttleState']).not.to.equal(null);
expect(typeof binding['throttleState']).to.equal('object');
});
it('unbind() should revert the original behavior', function () {
sut.unbind(undefined, undefined, binding as any);
expect(binding['throttledMethod']).to.equal(null);
expect(binding.updateTarget === originalFn).to.equal(true);
expect(typeof binding.updateTarget).to.equal('function');
expect(binding['throttleState']).to.equal(null);
});
});
示例6: container
public get container(): IContainer {
if (this._container === null) {
this._container = DI.createContainer(this.config);
Registration.instance(IDOM, this.dom).register(this._container);
Registration.instance(HTMLTestContext, this).register(this._container);
}
return this._container;
}
示例7: it
it('registers the custom attribute as transient', function () {
const { Type } = createCustomAttribute();
const container = DI.createContainer();
Type.register(container);
const resolved1 = container.get('custom-attribute:foo');
const resolved2 = container.get('custom-attribute:foo');
expect(resolved1).not.to.equal(resolved2);
});
示例8: 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);
}
示例9: beforeEach
beforeEach(function () {
container = DI.createContainer();
});