本文整理匯總了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();
});