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AE,GAAG;YACP,IAAM,QAAQ,GAAS,YAAa,CAAC,QAAQ,CAAC;YAC9C,IAAI,MAAM,GAAG,QAAQ,CAAC,4BAA4B,CAAC,SAAS,CAAC,CAAC;YAC9D,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YACtF,MAAM,CAAC,MAAM,CAAC;QAChB,CAAC,CAAC;QAEI,EAAG,CAAC,QAAQ,GAAG,IAAI,CAAC;QAE1B,MAAM,CAAC,EAAE,CAAC;IACZ,CAAC;IACH,0BAAC;AAAD,CAAC,AAtOD,IAsOC;AAtOY,2BAAmB,sBAsO/B,CAAA;AACY,iBAAS,GAAG,IAAI,mBAAmB,CAAC,WAAI,CAAC,CAAC","sourcesContent":["/**\nSome credit for this helper goes to http://github.com/YuzuJS/setImmediate\n*/\n\nimport { root } from './root';\n\nexport class ImmediateDefinition {\n setImmediate: (cb: () => void) => number;\n\n clearImmediate: (handle: number) => void;\n\n private identify(o: any): string {\n return this.root.Object.prototype.toString.call(o);\n }\n\n tasksByHandle: any;\n\n nextHandle: number;\n\n currentlyRunningATask: boolean;\n\n constructor(private root: any) {\n if (root.setImmediate && typeof root.setImmediate === 'function') {\n this.setImmediate = root.setImmediate.bind(root);\n this.clearImmediate = root.clearImmediate.bind(root);\n } else {\n this.nextHandle = 1;\n this.tasksByHandle = {};\n this.currentlyRunningATask = false;\n\n // Don't get fooled by e.g. browserify environments.\n if (this.canUseProcessNextTick()) {\n // For Node.js before 0.9\n this.setImmediate = this.createProcessNextTickSetImmediate();\n } else if (this.canUsePostMessage()) {\n // For non-IE10 modern browsers\n this.setImmediate = this.createPostMessageSetImmediate();\n } else if (this.canUseMessageChannel()) {\n // For web workers, where supported\n this.setImmediate = this.createMessageChannelSetImmediate();\n } else if (this.canUseReadyStateChange()) {\n // For IE 6–8\n this.setImmediate = this.createReadyStateChangeSetImmediate();\n } else {\n // For older browsers\n this.setImmediate = this.createSetTimeoutSetImmediate();\n }\n\n let ci = function clearImmediate(handle: any) {\n delete (<any>clearImmediate).instance.tasksByHandle[handle];\n };\n\n (<any>ci).instance = this;\n\n this.clearImmediate = ci;\n }\n }\n\n canUseProcessNextTick() {\n return this.identify(this.root.process) === '[object process]';\n }\n\n canUseMessageChannel() {\n return Boolean(this.root.MessageChannel);\n }\n\n canUseReadyStateChange() {\n const document = this.root.document;\n return Boolean(document && 'onreadystatechange' in document.createElement('script'));\n }\n\n canUsePostMessage() {\n const root = this.root;\n // The test against `importScripts` prevents this implementation from being installed inside a web worker,\n // where `root.postMessage` means something completely different and can't be used for this purpose.\n if (root.postMessage && !root.importScripts) {\n let postMessageIsAsynchronous = true;\n let oldOnMessage = root.onmessage;\n root.onmessage = function() {\n postMessageIsAsynchronous = false;\n };\n root.postMessage('', '*');\n root.onmessage = oldOnMessage;\n return postMessageIsAsynchronous;\n }\n\n return false;\n }\n\n // This function accepts the same arguments as setImmediate, but\n // returns a function that requires no arguments.\n partiallyApplied(handler: any, ...args: any[]) {\n let fn = function result () {\n const { handler, args } = <any>result;\n if (typeof handler === 'function') {\n handler.apply(undefined, args);\n } else {\n (new Function('' + handler))();\n }\n };\n\n (<any>fn).handler = handler;\n (<any>fn).args = args;\n\n return fn;\n }\n\n addFromSetImmediateArguments(args: any[]) {\n this.tasksByHandle[this.nextHandle] = this.partiallyApplied.apply(undefined, args);\n return this.nextHandle++;\n }\n\n createProcessNextTickSetImmediate() {\n let fn = function setImmediate() {\n const { instance } = (<any>setImmediate);\n let handle = instance.addFromSetImmediateArguments(arguments);\n instance.root.process.nextTick(instance.partiallyApplied(instance.runIfPresent, handle));\n return handle;\n };\n\n (<any>fn).instance = this;\n\n return fn;\n }\n\n createPostMessageSetImmediate() {\n // Installs an event handler on `global` for the `message` event: see\n // * https://developer.mozilla.org/en/DOM/window.postMessage\n // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages\n const root = this.root;\n\n let messagePrefix = 'setImmediate$' + root.Math.random() + '$';\n let onGlobalMessage = function globalMessageHandler(event: any) {\n const instance = (<any>globalMessageHandler).instance;\n if (event.source === root &&\n typeof event.data === 'string' &&\n event.data.indexOf(messagePrefix) === 0) {\n instance.runIfPresent(+event.data.slice(messagePrefix.length));\n }\n };\n (<any>onGlobalMessage).instance = this;\n\n root.addEventListener('message', onGlobalMessage, false);\n\n let fn = function setImmediate() {\n const { messagePrefix, instance } = (<any>setImmediate);\n let handle = instance.addFromSetImmediateArguments(arguments);\n instance.root.postMessage(messagePrefix + handle, '*');\n return handle;\n };\n\n (<any>fn).instance = this;\n (<any>fn).messagePrefix = messagePrefix;\n\n return fn;\n }\n\n runIfPresent(handle: any) {\n // From the spec: 'Wait until any invocations of this algorithm started before this one have completed.'\n // So if we're currently running a task, we'll need to delay this invocation.\n if (this.currentlyRunningATask) {\n // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a\n // 'too much recursion' error.\n this.root.setTimeout(this.partiallyApplied(this.runIfPresent, handle), 0);\n } else {\n let task = this.tasksByHandle[handle];\n if (task) {\n this.currentlyRunningATask = true;\n try {\n task();\n } finally {\n this.clearImmediate(handle);\n this.currentlyRunningATask = false;\n }\n }\n }\n }\n\n createMessageChannelSetImmediate() {\n let channel = new this.root.MessageChannel();\n channel.port1.onmessage = (event: any) => {\n let handle = event.data;\n this.runIfPresent(handle);\n };\n\n let fn = function setImmediate() {\n const { channel, instance } = (<any>setImmediate);\n let handle = instance.addFromSetImmediateArguments(arguments);\n channel.port2.postMessage(handle);\n return handle;\n };\n\n (<any>fn).channel = channel;\n (<any>fn).instance = this;\n\n return fn;\n }\n\n createReadyStateChangeSetImmediate() {\n let fn = function setImmediate() {\n const instance = (<any>setImmediate).instance;\n const root = instance.root;\n const doc = root.document;\n const html = doc.documentElement;\n\n let handle = instance.addFromSetImmediateArguments(arguments);\n // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted\n // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.\n let script = doc.createElement('script');\n script.onreadystatechange = () => {\n instance.runIfPresent(handle);\n script.onreadystatechange = null;\n html.removeChild(script);\n script = null;\n };\n html.appendChild(script);\n return handle;\n };\n\n (<any>fn).instance = this;\n\n return fn;\n }\n\n createSetTimeoutSetImmediate() {\n let fn = function setImmediate() {\n const instance = (<any>setImmediate).instance;\n let handle = instance.addFromSetImmediateArguments(arguments);\n instance.root.setTimeout(instance.partiallyApplied(instance.runIfPresent, handle), 0);\n return handle;\n };\n\n (<any>fn).instance = this;\n\n return fn;\n }\n}\nexport const Immediate = new ImmediateDefinition(root);\n"]}
|