本文整理汇总了TypeScript中typed-dom.once函数的典型用法代码示例。如果您正苦于以下问题:TypeScript once函数的具体用法?TypeScript once怎么用?TypeScript once使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了once函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('hash', function (done) {
const url = '/base/test/integration/fixture/basic/1.html#a';
new Pjax({}, { document, router });
const unbind = once(window, 'pjax:fetch', () => {
done(true);
});
once(document, 'click', ev => {
assert(!ev.defaultPrevented);
a.remove();
setTimeout(() => {
assert(window.location.hash === '#a');
once(window, 'hashchange', () => {
assert(window.location.hash === '');
setTimeout(() => {
unbind();
done();
}, 100);
});
window.history.back();
}, 100);
});
const a = document.createElement('a');
a.href = url;
document.body.appendChild(a);
a.click();
});
示例2: click
function click(url: string, callback: (ev: Event) => void): void {
const el: RouterEventSource.Anchor = document.createElement('a');
el.href = url;
void parse('').extract().body.appendChild(el);
void once(el, 'click', callback);
void once(el, 'click', ev => void ev.preventDefault());
void el.click();
}
示例3: once
once(window, 'pjax:load', () => {
pjax.assign(url);
once(document, 'pjax:ready', () => {
assert(window.location.pathname === url);
assert(document.title === 'Title 2');
assert(document.querySelector('#primary')!.textContent === 'Primary 2');
done();
});
});
示例4: it
it('normal', function () {
const document = parse('<a href=""></a>').extract();
assert(new GUI({}, { document, router: (_, ev) => {
ev.original.preventDefault();
return true;
}}));
once(document, 'a', 'click', ev => {
assert(ev.defaultPrevented === true);
});
document.querySelector('a')!.click();
});
示例5: setTimeout
setTimeout(() => {
assert(window.location.hash === '#a');
once(window, 'hashchange', () => {
assert(window.location.hash === '');
setTimeout(() => {
unbind();
done();
}, 100);
});
window.history.back();
}, 100);
示例6: it
it('basic', function (done) {
const url = '/base/test/integration/fixture/basic/1.html';
const document = parse('').extract();
new Pjax({}, { document, router })
.replace(url);
once(document, 'pjax:ready', () => {
assert(window.location.pathname === url);
assert(document.title === 'Title 1');
assert(document.querySelector('#primary')!.textContent === 'Primary 1');
done();
});
});
示例7: it
it('sequence', function (done) {
const path = '/base/test/integration/fixture/basic/2.html';
const document = parse('').extract();
new Pjax({
fallback: done
}, { document, router })
.assign(path);
let cnt = 0;
once(window, 'pjax:fetch', ev => {
assert(ev instanceof Event);
assert(window.history.scrollRestoration === 'manual');
assert(cnt === 0 && ++cnt);
});
once(window, 'pjax:unload', ev => {
assert(ev instanceof Event);
assert(window.history.scrollRestoration === 'auto');
assert(window.location.pathname !== path);
assert(cnt === 1 && ++cnt);
});
once(document, 'pjax:content', ev => {
assert(ev instanceof Event);
assert(window.history.scrollRestoration === 'auto');
assert(window.location.pathname === path);
assert(document.title === 'Title 2');
assert(document.querySelector('header')!.innerHTML === 'Header 2');
assert(cnt === 2 && ++cnt);
});
once(document, 'pjax:ready', ev => {
assert(ev instanceof Event);
assert(window.history.scrollRestoration === 'auto');
assert(cnt === 3 && ++cnt);
});
once(window, 'pjax:load', ev => {
assert(ev instanceof Event);
assert(window.history.scrollRestoration === 'auto');
assert(cnt === 4 && ++cnt);
done();
});
});
示例8: it
it('basic', function (done) {
const url1 = '/base/test/integration/fixture/basic/1.html';
const url2 = '/base/test/integration/fixture/basic/2.html';
const document = parse('').extract();
Pjax.assign(url1, { fallback: done }, { document, router });
Pjax.assign(url2, { fallback: done }, { document, router });
once(document, 'pjax:ready', () => {
assert(window.location.pathname === url2);
assert(document.title === 'Title 2');
assert(document.querySelector('#primary')!.textContent === 'Primary 2');
setTimeout(done, 1000);
});
});
示例9: it
it('submit external', function (done) {
const url = '//external';
const form = html('form', { action: url }, [
html('input', { type: 'submit', value: 'submit' }),
]);
document.body.appendChild(form);
once(document, 'form', 'submit', ev => {
assert(!validate(new URL(standardize(url)), new Config({}), new RouterEvent(ev)));
ev.preventDefault();
form.remove();
done();
});
form.querySelector('input')!.click();
});