Skip to content

Commit

Permalink
fix(Immediate): update setImmediate compatibility on IE
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jan 11, 2016
1 parent 41d39e2 commit 39e6c0e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 16 additions & 4 deletions spec/util/Immediate-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ describe('ImmediateDefinition', function () {

describe('when setImmediate exists on root', function () {
it('should use the setImmediate and clearImmediate methods from root', function () {
var setImmediateCalled = false;
var clearImmediateCalled = false;

var root = {
setImmediate: function () {},
clearImmediate: function () {}
setImmediate: function () {
setImmediateCalled = true;
},
clearImmediate: function () {
clearImmediateCalled = true;
}
};

var result = new ImmediateDefinition(root);
expect(result.setImmediate).toBe(root.setImmediate);
expect(result.clearImmediate).toBe(root.clearImmediate);

result.setImmediate(function () {});
result.clearImmediate();

expect(setImmediateCalled).toBeTruthy();
expect(clearImmediateCalled).toBeTruthy();
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/util/Immediate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export class ImmediateDefinition {
currentlyRunningATask: boolean;

constructor(private root: any) {
if (root.setImmediate) {
this.setImmediate = root.setImmediate;
this.clearImmediate = root.clearImmediate;
if (root.setImmediate && typeof root.setImmediate === 'function') {
this.setImmediate = root.setImmediate.bind(root);
this.clearImmediate = root.clearImmediate.bind(root);
} else {
this.nextHandle = 1;
this.tasksByHandle = {};
Expand Down

0 comments on commit 39e6c0e

Please sign in to comment.