當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript typed-dom.once函數代碼示例

本文整理匯總了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();
 });
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:26,代碼來源:click.ts

示例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();
}
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:8,代碼來源:api.ts

示例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();
   });
 });
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:9,代碼來源:cache.ts

示例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();
 });
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:11,代碼來源:gui.test.ts

示例5: setTimeout

 setTimeout(() => {
   assert(window.location.hash === '#a');
   once(window, 'hashchange', () => {
     assert(window.location.hash === '');
     setTimeout(() => {
       unbind();
       done();
     }, 100);
   });
   window.history.back();
 }, 100);
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:11,代碼來源:click.ts

示例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();
   });
 });
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:12,代碼來源:replace.ts

示例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();
   });
 });
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:39,代碼來源:package.ts

示例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);
   });
 });
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:13,代碼來源:cancel.ts

示例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();
 });
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:14,代碼來源:router.test.ts


注:本文中的typed-dom.once函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。