本文整理汇总了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);
}
示例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);
});
示例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);
});
示例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);
});
示例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);
}
示例6: blur
export function blur(element: Element): Promise<void> {
element.dispatchEvent(DOM.createCustomEvent('blur', {}));
return new Promise<void>(setTimeout);
}
示例7: setInterval
let updateSourceInterval = setInterval(() => {
// console.info('dispatching');
target.dispatchEvent(DOM.createCustomEvent('mousemove'));
}, 20);