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


TypeScript DOM.createCustomEvent方法代码示例

本文整理汇总了TypeScript中aurelia-pal.DOM.createCustomEvent方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DOM.createCustomEvent方法的具体用法?TypeScript DOM.createCustomEvent怎么用?TypeScript DOM.createCustomEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aurelia-pal.DOM的用法示例。


在下文中一共展示了DOM.createCustomEvent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: exerciseBehavior

    function exerciseBehavior(callback) {
      let sourceCalls = 0;
      let source = {
        handleClick: e => {
          // console.info('source called');
          sourceCalls++;
        }
      };
      let scope = createScopeForTest(source);

      // overrides updateSource
      binding.bind(scope);
      expect(binding.callSource === originalCallSource).not.toBe(true);

      for (let i = 0, ii = 50; i < ii; i++) {
        button.dispatchEvent(DOM.createCustomEvent('click', { bubbles: true }));
      }

      // How to ensure this happen after all events without timeout?
      let testDuration = 500;
      function endTest() {
        binding.unbind();
        expect(sourceCalls).toEqual(0);
        expect(binding.callSource === originalCallSource).toBe(true);
        callback();
      }
      setTimeout(endTest, testDuration);
    }
开发者ID:aurelia,项目名称:templating-resources,代码行数:28,代码来源:self-binding-behavior.spec.ts

示例2: it

  it('should set focus value to true when element gets focus', () => {
    focus.attached();
    setBindedFocusValue(false);

    element.dispatchEvent(DOM.createCustomEvent('focus'));

    expect(focus.value).toBe(true);
  });
开发者ID:aurelia,项目名称:templating-resources,代码行数:8,代码来源:focus.spec.ts

示例3: it

  it('should apply update trigger events', () => {
    let source = { foo: 'bar' };
    let scope = createScopeForTest(source);
    let target = document.createElement('input');
    let bindingExpression = bindingEngine.createBindingExpression('value', `foo & updateTrigger:'blur':'paste'`, bindingMode.twoWay, lookupFunctions);
    let binding = bindingExpression.createBinding(target);

    binding.bind(scope);
    let targetHandler = binding.targetObserver.handler;

    target.value = 'baz';
    target.dispatchEvent(DOM.createCustomEvent('change'));
    expect(source.foo).toBe('bar');
    target.dispatchEvent(DOM.createCustomEvent('blur'));
    expect(source.foo).toBe('baz');

    target.value = 'bang';
    target.dispatchEvent(DOM.createCustomEvent('change'));
    expect(source.foo).toBe('baz');
    target.dispatchEvent(DOM.createCustomEvent('paste'));
    expect(source.foo).toBe('bang');


    binding.unbind();

    target.value = 'target';
    target.dispatchEvent(DOM.createCustomEvent('blur'));
    expect(source.foo).toBe('bang');
    target.dispatchEvent(DOM.createCustomEvent('paste'));
    expect(source.foo).toBe('bang');

    // also makes sure we disposed the listeners
    expect(targetHandler.element).toBe(null);
  });
开发者ID:aurelia,项目名称:templating-resources,代码行数:34,代码来源:update-trigger-binding-behavior.spec.ts

示例4: it

  it('should debounce call source', () => {
    let target = document.createElement('div');
    let delay = 150;
    let bindingExpression = new (AureliaBinding as any).ListenerExpression(
      bindingEngine.observerLocator.eventManager,
      'mousemove',
      bindingEngine.parseExpression(`handleMouseMove($event) & debounce:${delay}`),
      delegationStrategy.none,
      false,
      lookupFunctions
    );

    let binding = bindingExpression.createBinding(target);
    let originalCallSource = binding.callSource;

    let viewModel = {
      callCount: 0,
      handleMouseMove: e => {
        viewModel.callCount++;
      }
    };
    let scope = createScopeForTest(viewModel);

    // overrides callSource
    binding.bind(scope);
    expect(binding.callSource === originalCallSource).not.toBe(true);

    let exerciseCount = 10;
    let callCount = 0;
    while (exerciseCount--) {
      let tick = Math.floor(Math.random() * delay + delay / 3);
      let shouldCall = tick >= delay;

      target.dispatchEvent(DOM.createCustomEvent('mousemove'));
      jasmine.clock().tick(tick);

      callCount += Number(shouldCall);
    }

    expect(callCount).toBe(viewModel.callCount);
    binding.unbind();
    expect(binding.callSource === originalCallSource).toBe(true);
  });
开发者ID:aurelia,项目名称:templating-resources,代码行数:43,代码来源:debounce-binding-behavior.spec.ts

示例5: change

export function change(element: HTMLInputElement, value: string): Promise<void> {
  element.value = value;
  element.dispatchEvent(DOM.createCustomEvent('change', { bubbles: true }));
  return new Promise<void>(setTimeout);
}
开发者ID:manuel-guilbault,项目名称:aurelia-validation,代码行数:5,代码来源:shared.ts

示例6: blur

export function blur(element: Element): Promise<void> {
  element.dispatchEvent(DOM.createCustomEvent('blur', {}));
  return new Promise<void>(setTimeout);
}
开发者ID:manuel-guilbault,项目名称:aurelia-validation,代码行数:4,代码来源:shared.ts

示例7: setInterval

 let updateSourceInterval = setInterval(() => {
   // console.info('dispatching');
   target.dispatchEvent(DOM.createCustomEvent('mousemove'));
 }, 20);
开发者ID:aurelia,项目名称:templating-resources,代码行数:4,代码来源:throttle-binding-behavior.spec.ts


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