本文整理汇总了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;未经允许,请勿转载。 |
请发表评论