Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(root): a slightly more concise definition borrowed from Angular #2593

Merged
merged 2 commits into from May 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 26 additions & 26 deletions src/util/root.ts
@@ -1,29 +1,29 @@
declare let global: NodeJS.Global;

declare module NodeJS {
interface Global {
window: any;
global: any;
}
}
declare let global: any;

/**
* window: browser in DOM main thread
* self: browser in WebWorker
* global: Node.js/other
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export let root: any;
if (typeof window == 'object' && window.window === window) {
root = window;
} else if (typeof self == 'object' && self.self === self) {
root = self;
} else if (typeof global == 'object' && global.global === global) {
root = global;
} else {
// Workaround Closure Compiler restriction: The body of a goog.module cannot use throw.
// This is needed when used with angular/tsickle which inserts a goog.module statement.
// Wrap in IIFE
(function () {
throw new Error('RxJS could not find any global context (window, self, global)');
})();
}

declare var WorkerGlobalScope: any;
// CommonJS / Node have global context exposed as "global" variable.
// We don't want to include the whole node.d.ts this this compilation unit so we'll just fake
// the global "global" var for now.

const __window = typeof window !== 'undefined' && window;
const __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
self instanceof WorkerGlobalScope && self;
const __global = typeof global !== 'undefined' && global;
const _root: any = __window || __global || __self;

// Workaround Closure Compiler restriction: The body of a goog.module cannot use throw.
// This is needed when used with angular/tsickle which inserts a goog.module statement.
// Wrap in IIFE
(function () {
throw new Error('RxJS could not find any global context (window, self, global)');
})();

export { _root as root };