File tree Expand file tree Collapse file tree 2 files changed +21
-13
lines changed Expand file tree Collapse file tree 2 files changed +21
-13
lines changed Original file line number Diff line number Diff line change
1
+ import { expect } from 'chai' ;
2
+ import { root } from '../../dist/cjs/util/root' ;
3
+
4
+ /** @test {root} */
5
+ describe ( 'root' , ( ) => {
6
+ it ( 'should exist' , ( ) => {
7
+ expect ( typeof root ) . to . equal ( 'object' ) ;
8
+ } ) ;
9
+ } ) ;
Original file line number Diff line number Diff line change 1
- let objectTypes = {
2
- 'boolean' : false ,
3
- 'function' : true ,
4
- 'object' : true ,
5
- 'number' : false ,
6
- 'string' : false ,
7
- 'undefined' : false
8
- } ;
9
-
10
1
declare let global : NodeJS . Global ;
11
2
declare let module : any ;
12
3
declare let exports : any ;
@@ -18,9 +9,17 @@ declare module NodeJS {
18
9
}
19
10
}
20
11
21
- export let root : any = ( objectTypes [ typeof self ] && self ) || ( objectTypes [ typeof window ] && window ) ;
12
+ /**
13
+ * window: browser in DOM main thread
14
+ * self: browser in WebWorker
15
+ * global: Node.js/other
16
+ */
17
+ export const root : any = (
18
+ typeof window == 'object' && window . window === window && window
19
+ || typeof self == 'object' && self . self === self && self
20
+ || typeof global == 'object' && global . global === global && global
21
+ ) ;
22
22
23
- let freeGlobal = objectTypes [ typeof global ] && global ;
24
- if ( freeGlobal && ( freeGlobal . global === freeGlobal || freeGlobal . window === freeGlobal ) ) {
25
- root = freeGlobal ;
23
+ if ( ! root ) {
24
+ throw new Error ( 'RxJS could not find any global context (window, self, global)' ) ;
26
25
}
You can’t perform that action at this time.
0 commit comments