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


TypeScript kernel.DI类代码示例

本文整理汇总了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);
  });
});
开发者ID:aurelia,项目名称:aurelia,代码行数:27,代码来源:self-binding-behavior.spec.ts

示例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);
        });
      });
    }
  }
});
开发者ID:aurelia,项目名称:aurelia,代码行数:28,代码来源:binding-mode-behaviors.spec.ts

示例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);
  });
});
开发者ID:aurelia,项目名称:aurelia,代码行数:31,代码来源:debounce-binding-behavior.spec.ts

示例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);
        });
开发者ID:aurelia,项目名称:aurelia,代码行数:33,代码来源:attribute-pattern.spec.ts

示例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);
  });
});
开发者ID:aurelia,项目名称:aurelia,代码行数:31,代码来源:throttle-binding-behavior.spec.ts

示例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;
 }
开发者ID:aurelia,项目名称:aurelia,代码行数:8,代码来源:util.ts

示例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);
    });
开发者ID:aurelia,项目名称:aurelia,代码行数:10,代码来源:custom-attribute.register.spec.ts

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

示例9: beforeEach

 beforeEach(function () {
   container = DI.createContainer();
 });
开发者ID:aurelia,项目名称:aurelia,代码行数:3,代码来源:binding-behavior.spec.ts


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