Skip to content

Commit

Permalink
Bind clock methods to global thisArg.
Browse files Browse the repository at this point in the history
Fixes #1703
  • Loading branch information
blimmer committed Dec 7, 2020
1 parent cd711ba commit 8a8cfa3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-apes-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': patch
---

The `clock` methods (`setTimeout`, `clearTimeout`) are now properly bound to the `global` scope internally (fixes #1703)
4 changes: 2 additions & 2 deletions packages/core/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ export class Interpreter<
deferEvents: true,
clock: {
setTimeout: (fn, ms) => {
return global.setTimeout.call(null, fn, ms);
return global.setTimeout.call(global, fn, ms);
},
clearTimeout: (id) => {
return global.clearTimeout.call(null, id);
return global.clearTimeout.call(global, id);
}
},
logger: global.console.log.bind(console),
Expand Down

0 comments on commit 8a8cfa3

Please sign in to comment.