Skip to content
Snippets Groups Projects
Commit 0c7c82e0 authored by David Sehnal's avatar David Sehnal
Browse files

Scheduler tweaks

parent 8416a827
No related branches found
No related tags found
No related merge requests found
...@@ -89,7 +89,7 @@ function createImmediateActions() { ...@@ -89,7 +89,7 @@ function createImmediateActions() {
function canUsePostMessage() { function canUsePostMessage() {
// The test against `importScripts` prevents this implementation from being installed inside a web worker, // The test against `importScripts` prevents this implementation from being installed inside a web worker,
// where `global.postMessage` means something completely different and can't be used for this purpose. // where `global.postMessage` means something completely different and can't be used for this purpose.
const global = window as any; const global = typeof window !== 'undefined' ? window as any : void 0;
if (global && global.postMessage && !global.importScripts) { if (global && global.postMessage && !global.importScripts) {
let postMessageIsAsynchronous = true; let postMessageIsAsynchronous = true;
const oldOnMessage = global.onmessage; const oldOnMessage = global.onmessage;
...@@ -108,6 +108,7 @@ function createImmediateActions() { ...@@ -108,6 +108,7 @@ function createImmediateActions() {
// * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
const messagePrefix = 'setImmediate$' + Math.random() + '$'; const messagePrefix = 'setImmediate$' + Math.random() + '$';
const global = typeof window !== 'undefined' ? window as any : void 0;
const onGlobalMessage = function(event: any) { const onGlobalMessage = function(event: any) {
if (event.source === global && if (event.source === global &&
typeof event.data === 'string' && typeof event.data === 'string' &&
...@@ -187,7 +188,9 @@ function createImmediateActions() { ...@@ -187,7 +188,9 @@ function createImmediateActions() {
const immediateActions = (function () { const immediateActions = (function () {
if (typeof setImmediate !== 'undefined') { if (typeof setImmediate !== 'undefined') {
return { setImmediate, clearImmediate }; if (typeof window !== 'undefined') {
return { setImmediate: (handler: any, ...args: any[]) => window.setImmediate(handler, ...args as any), clearImmediate: (handle: any) => window.clearImmediate(handle) };
} else return { setImmediate, clearImmediate }
} }
return createImmediateActions(); return createImmediateActions();
}()); }());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment