|
1 | | -import setGlobalContext from '@glimmer/global-context'; |
| 1 | +import setGlobalContextVM from '@glimmer/global-context'; |
2 | 2 | import { EnvironmentDelegate } from '@glimmer/runtime'; |
3 | 3 | import { Option, Destructor, Destroyable } from '@glimmer/interfaces'; |
4 | 4 | import { IteratorDelegate } from '@glimmer/reference'; |
5 | 5 |
|
6 | 6 | import { isNativeIterable, NativeIterator } from './iterator'; |
7 | 7 | import { DEBUG } from '@glimmer/env'; |
8 | 8 | import toBool from './to-bool'; |
9 | | -import { scheduleRevalidate } from '../render-component'; |
10 | 9 |
|
11 | 10 | let scheduledDestroyables: Destroyable[] = []; |
12 | 11 | let scheduledDestructors: Destructor<object>[] = []; |
13 | 12 | let scheduledFinishDestruction: (() => void)[] = []; |
14 | 13 |
|
15 | | -setGlobalContext({ |
16 | | - getProp(obj: Record<string, unknown>, key: string) { |
17 | | - return obj[key]; |
18 | | - }, |
19 | | - |
20 | | - setProp(obj: Record<string, unknown>, key: string, newValue: unknown) { |
21 | | - obj[key] = newValue; |
22 | | - }, |
23 | | - |
24 | | - getPath(obj: Record<string, unknown>, key: string) { |
25 | | - if (DEBUG && key.includes('.')) { |
26 | | - throw new Error( |
27 | | - 'You attempted to get a path with a `.` in it, but Glimmer.js does not support paths with dots.' |
28 | | - ); |
29 | | - } |
30 | | - |
31 | | - return obj[key]; |
32 | | - }, |
33 | | - |
34 | | - setPath(obj: Record<string, unknown>, key: string, newValue: unknown) { |
35 | | - if (DEBUG && key.includes('.')) { |
36 | | - throw new Error( |
37 | | - 'You attempted to set a path with a `.` in it, but Glimmer.js does not support paths with dots.' |
38 | | - ); |
39 | | - } |
40 | | - |
41 | | - obj[key] = newValue; |
42 | | - }, |
43 | | - |
44 | | - scheduleRevalidate, |
45 | | - |
46 | | - toBool, |
47 | | - |
48 | | - toIterator(value: unknown): Option<IteratorDelegate> { |
49 | | - if (isNativeIterable(value)) { |
50 | | - return NativeIterator.from(value); |
51 | | - } |
52 | | - |
53 | | - return null; |
54 | | - }, |
55 | | - |
56 | | - scheduleDestroy(destroyable, destructor) { |
57 | | - scheduledDestroyables.push(destroyable); |
58 | | - scheduledDestructors.push(destructor); |
59 | | - }, |
60 | | - |
61 | | - scheduleDestroyed(fn) { |
62 | | - scheduledFinishDestruction.push(fn); |
63 | | - }, |
64 | | - |
65 | | - warnIfStyleNotTrusted() { |
66 | | - // Do nothing |
67 | | - }, |
68 | | - |
69 | | - assert(test: unknown, msg: string) { |
70 | | - if (!test) { |
71 | | - throw new Error(msg); |
72 | | - } |
73 | | - }, |
74 | | - |
75 | | - deprecate(msg: string, test: unknown) { |
76 | | - if (!test) { |
77 | | - console.warn(msg); |
78 | | - } |
79 | | - }, |
80 | | -}); |
| 14 | +export function setGlobalContext(scheduleRevalidate: () => void): void { |
| 15 | + setGlobalContextVM({ |
| 16 | + getProp(obj: Record<string, unknown>, key: string) { |
| 17 | + return obj[key]; |
| 18 | + }, |
| 19 | + |
| 20 | + setProp(obj: Record<string, unknown>, key: string, newValue: unknown) { |
| 21 | + obj[key] = newValue; |
| 22 | + }, |
| 23 | + |
| 24 | + getPath(obj: Record<string, unknown>, key: string) { |
| 25 | + if (DEBUG && key.includes('.')) { |
| 26 | + throw new Error( |
| 27 | + 'You attempted to get a path with a `.` in it, but Glimmer.js does not support paths with dots.' |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + return obj[key]; |
| 32 | + }, |
| 33 | + |
| 34 | + setPath(obj: Record<string, unknown>, key: string, newValue: unknown) { |
| 35 | + if (DEBUG && key.includes('.')) { |
| 36 | + throw new Error( |
| 37 | + 'You attempted to set a path with a `.` in it, but Glimmer.js does not support paths with dots.' |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + obj[key] = newValue; |
| 42 | + }, |
| 43 | + |
| 44 | + scheduleRevalidate, |
| 45 | + |
| 46 | + toBool, |
| 47 | + |
| 48 | + toIterator(value: unknown): Option<IteratorDelegate> { |
| 49 | + if (isNativeIterable(value)) { |
| 50 | + return NativeIterator.from(value); |
| 51 | + } |
| 52 | + |
| 53 | + return null; |
| 54 | + }, |
| 55 | + |
| 56 | + scheduleDestroy(destroyable, destructor) { |
| 57 | + scheduledDestroyables.push(destroyable); |
| 58 | + scheduledDestructors.push(destructor); |
| 59 | + }, |
| 60 | + |
| 61 | + scheduleDestroyed(fn) { |
| 62 | + scheduledFinishDestruction.push(fn); |
| 63 | + }, |
| 64 | + |
| 65 | + warnIfStyleNotTrusted() { |
| 66 | + // Do nothing |
| 67 | + }, |
| 68 | + |
| 69 | + assert(test: unknown, msg: string) { |
| 70 | + if (!test) { |
| 71 | + throw new Error(msg); |
| 72 | + } |
| 73 | + }, |
| 74 | + |
| 75 | + deprecate(msg: string, test: unknown) { |
| 76 | + if (!test) { |
| 77 | + console.warn(msg); |
| 78 | + } |
| 79 | + }, |
| 80 | + }); |
| 81 | +} |
81 | 82 |
|
82 | 83 | /** |
83 | 84 | * The environment delegate base class shared by both the client and SSR |
|
0 commit comments