From 0c7c82e043eca0a33c2b5cf37d437c0d22d090b3 Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Tue, 14 Nov 2017 02:34:42 +0100
Subject: [PATCH] Scheduler tweaks

---
 src/mol-util/scheduler.ts | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/mol-util/scheduler.ts b/src/mol-util/scheduler.ts
index 85ad75eff..e118ec97c 100644
--- a/src/mol-util/scheduler.ts
+++ b/src/mol-util/scheduler.ts
@@ -89,7 +89,7 @@ function createImmediateActions() {
     function canUsePostMessage() {
         // 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.
-        const global = window as any;
+        const global = typeof window !== 'undefined' ? window as any : void 0;
         if (global && global.postMessage && !global.importScripts) {
             let postMessageIsAsynchronous = true;
             const oldOnMessage = global.onmessage;
@@ -108,6 +108,7 @@ function createImmediateActions() {
         // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
 
         const messagePrefix = 'setImmediate$' + Math.random() + '$';
+        const global = typeof window !== 'undefined' ? window as any : void 0;
         const onGlobalMessage = function(event: any) {
             if (event.source === global &&
                 typeof event.data === 'string' &&
@@ -187,7 +188,9 @@ function createImmediateActions() {
 
 const immediateActions = (function () {
     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();
 }());
-- 
GitLab