• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript backburner.run函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中backburner.run函数的典型用法代码示例。如果您正苦于以下问题:TypeScript run函数的具体用法?TypeScript run怎么用?TypeScript run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了run函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: function

QUnit.test('onError with target and action', function(assert) {
  assert.expect(3);

  let target = {};

  let bb = new Backburner(['errors'], {
    onErrorTarget: target,
    onErrorMethod: 'onerror'
  });

  bb.run(() => assert.ok(true));

  target['onerror'] = function(error) {
    assert.equal('QUnit.test error', error.message);
  };

  bb.run(() => { throw new Error('QUnit.test error'); });

  target['onerror'] = function() { };

  bb.run(() => { throw new Error('QUnit.test error'); });

  target['onerror'] = function(error) {
    assert.equal('QUnit.test error', error.message);
  };

  bb.run(() => { throw new Error('QUnit.test error'); });
});
开发者ID:ebryn,项目名称:backburner.js,代码行数:28,代码来源:run-test.ts


示例2: function

QUnit.test('when passed same function twice with different target and different arguments', function(assert) {
  assert.expect(7);

  let bb = new Backburner(['one']);
  let i = 0;

  function deferMethod(a, b) {
    i++;
    if (i === 1) {
      assert.equal(a, 1, 'First argument set during first call');
    } else {
      assert.equal(a, 3, 'First argument set during second call');
    }
    assert.equal(b, 2, 'Second argument remains same');
    assert.equal(this['first'], 1, 'the target property was set');
  }

  let argObj = {first: 1};

  bb.run(() => {
    bb.scheduleOnce('one', {first: 1}, deferMethod, 1, 2);
    bb.scheduleOnce('one', {first: 1}, deferMethod, 3, 2);
  });

  assert.equal(i, 2, 'function was called twice');
});
开发者ID:ebryn,项目名称:backburner.js,代码行数:26,代码来源:defer-once-test.ts


示例3: function

QUnit.test('end event should fire before onEnd', function(assert) {
  assert.expect(3);
  let callNumber = 0;

  let bb = new Backburner(['one', 'two'], {
    onEnd() {
      assert.equal(callNumber, 1);
    }
  });

  bb.on('end', () => callNumber++);

  function funcOne() {
    assert.equal(callNumber, 0);
  }

  function funcTwo() {
    assert.equal(callNumber, 0);
  }

  bb.run(() => {
    bb.schedule('one', null, funcOne);
    bb.schedule('two', null, funcTwo);
  });
});
开发者ID:ebryn,项目名称:backburner.js,代码行数:25,代码来源:events-test.ts


示例4:

  bb.run(() => {
    assert.equal(step++, 0);

    bb.run(() => {
      assert.equal(step++, 1);
    });
  });
开发者ID:ebryn,项目名称:backburner.js,代码行数:7,代码来源:run-test.ts


示例5: function

QUnit.test('cancel always returns boolean', function(assert) {
  let bb = new Backburner(['one']);

  bb.run(function() {
    let timer1 = bb.schedule('one', null, function() {});
    assert.equal(bb.cancel(timer1), true);
    assert.equal(bb.cancel(timer1), false);
    assert.equal(bb.cancel(timer1), false);

    let timer2 = bb.later(function() {}, 10);
    assert.equal(bb.cancel(timer2), true);
    assert.equal(bb.cancel(timer2), false);
    assert.equal(bb.cancel(timer2), false);

    let timer3 = bb.debounce(function() {}, 10);
    assert.equal(bb.cancel(timer3), true);
    assert.equal(bb.cancel(timer3), false);
    assert.equal(bb.cancel(timer3), false);

    assert.equal(bb.cancel(undefined), false);
    assert.equal(bb.cancel(null), false);
    assert.equal(bb.cancel({}), false);
    assert.equal(bb.cancel([]), false);
    assert.equal(bb.cancel(42), false);
    assert.equal(bb.cancel('42'), false);
  });
});
开发者ID:ebryn,项目名称:backburner.js,代码行数:27,代码来源:cancel-test.ts


示例6: function

QUnit.test('onBegin and onEnd are called and passed the correct parameters', function(assert) {
  assert.expect(2);

  let befores: Array<any | null | undefined> = [];
  let afters: Array<any | null | undefined> = [];
  let expectedBefores: Array<any | null | undefined> = [];
  let expectedAfters: Array<any | null | undefined> = [];
  let outer: any;
  let inner: any;

  let bb = new Backburner(['one'], {
    onBegin: function(current, previous) {
      befores.push(current);
      befores.push(previous);
    },
    onEnd: function(current, next) {
      afters.push(current);
      afters.push(next);
    }
  });

  bb.run(function() {
    outer = bb.currentInstance;
    bb.run(function() {
      inner = bb.currentInstance;
    });
  });

  expectedBefores = [outer, null, inner, outer];
  expectedAfters = [inner, outer, outer, null];

  assert.deepEqual(befores, expectedBefores, 'before callbacks successful');
  assert.deepEqual(afters, expectedAfters, 'after callback successful');
});
开发者ID:ebryn,项目名称:backburner.js,代码行数:34,代码来源:queue-test.ts



注:本文中的backburner.run函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript backburner.schedule函数代码示例发布时间:2022-05-25
下一篇:
TypeScript backburner.on函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap