当前位置: 首页>>代码示例>>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;未经允许,请勿转载。