1 | import { IS_PRODUCTION } from './environment.js';
|
2 |
|
3 | function getGlobal() {
|
4 | if (typeof globalThis !== 'undefined') {
|
5 | return globalThis;
|
6 | }
|
7 |
|
8 | if (typeof self !== 'undefined') {
|
9 | return self;
|
10 | }
|
11 |
|
12 | if (typeof window !== 'undefined') {
|
13 | return window;
|
14 | }
|
15 |
|
16 | if (typeof global !== 'undefined') {
|
17 | return global;
|
18 | }
|
19 |
|
20 | if (!IS_PRODUCTION) {
|
21 | console.warn('XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues');
|
22 | }
|
23 | }
|
24 |
|
25 | function getDevTools() {
|
26 | var global = getGlobal();
|
27 |
|
28 | if (global && '__xstate__' in global) {
|
29 | return global.__xstate__;
|
30 | }
|
31 |
|
32 | return undefined;
|
33 | }
|
34 |
|
35 | function registerService(service) {
|
36 | if (!getGlobal()) {
|
37 | return;
|
38 | }
|
39 |
|
40 | var devTools = getDevTools();
|
41 |
|
42 | if (devTools) {
|
43 | devTools.register(service);
|
44 | }
|
45 | }
|
46 |
|
47 | export { getGlobal, registerService };
|