1 | import { globalState, isolateGlobalState, setReactionScheduler } from "../internal"
|
2 |
|
3 | const NEVER = "never"
|
4 | const ALWAYS = "always"
|
5 | const OBSERVED = "observed"
|
6 |
|
7 |
|
8 | export function configure(options: {
|
9 | enforceActions?: "never" | "always" | "observed"
|
10 | computedRequiresReaction?: boolean
|
11 | |
12 |
|
13 |
|
14 | reactionRequiresObservable?: boolean
|
15 | |
16 |
|
17 |
|
18 | observableRequiresReaction?: boolean
|
19 | isolateGlobalState?: boolean
|
20 | disableErrorBoundaries?: boolean
|
21 | safeDescriptors?: boolean
|
22 | reactionScheduler?: (f: () => void) => void
|
23 | useProxies?: "always" | "never" | "ifavailable"
|
24 | }): void {
|
25 | if (options.isolateGlobalState === true) {
|
26 | isolateGlobalState()
|
27 | }
|
28 | const { useProxies, enforceActions } = options
|
29 | if (useProxies !== undefined) {
|
30 | globalState.useProxies =
|
31 | useProxies === ALWAYS
|
32 | ? true
|
33 | : useProxies === NEVER
|
34 | ? false
|
35 | : typeof Proxy !== "undefined"
|
36 | }
|
37 | if (useProxies === "ifavailable") globalState.verifyProxies = true
|
38 | if (enforceActions !== undefined) {
|
39 | const ea = enforceActions === ALWAYS ? ALWAYS : enforceActions === OBSERVED
|
40 | globalState.enforceActions = ea
|
41 | globalState.allowStateChanges = ea === true || ea === ALWAYS ? false : true
|
42 | }
|
43 | ;[
|
44 | "computedRequiresReaction",
|
45 | "reactionRequiresObservable",
|
46 | "observableRequiresReaction",
|
47 | "disableErrorBoundaries",
|
48 | "safeDescriptors"
|
49 | ].forEach(key => {
|
50 | if (key in options) globalState[key] = !!options[key]
|
51 | })
|
52 | globalState.allowStateReads = !globalState.observableRequiresReaction
|
53 | if (__DEV__ && globalState.disableErrorBoundaries === true) {
|
54 | console.warn(
|
55 | "WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled."
|
56 | )
|
57 | }
|
58 | if (options.reactionScheduler) {
|
59 | setReactionScheduler(options.reactionScheduler)
|
60 | }
|
61 | }
|