diff --git a/packages/@glimmer/core/src/environment/delegates.ts b/packages/@glimmer/core/src/environment/delegates.ts index 12b868762..c73cd11c9 100644 --- a/packages/@glimmer/core/src/environment/delegates.ts +++ b/packages/@glimmer/core/src/environment/delegates.ts @@ -1,4 +1,4 @@ -import setGlobalContext from '@glimmer/global-context'; +import setGlobalContextVM from '@glimmer/global-context'; import { EnvironmentDelegate } from '@glimmer/runtime'; import { Option, Destructor, Destroyable } from '@glimmer/interfaces'; import { IteratorDelegate } from '@glimmer/reference'; @@ -6,78 +6,79 @@ import { IteratorDelegate } from '@glimmer/reference'; import { isNativeIterable, NativeIterator } from './iterator'; import { DEBUG } from '@glimmer/env'; import toBool from './to-bool'; -import { scheduleRevalidate } from '../render-component'; let scheduledDestroyables: Destroyable[] = []; let scheduledDestructors: Destructor[] = []; let scheduledFinishDestruction: (() => void)[] = []; -setGlobalContext({ - getProp(obj: Record, key: string) { - return obj[key]; - }, - - setProp(obj: Record, key: string, newValue: unknown) { - obj[key] = newValue; - }, - - getPath(obj: Record, key: string) { - if (DEBUG && key.includes('.')) { - throw new Error( - 'You attempted to get a path with a `.` in it, but Glimmer.js does not support paths with dots.' - ); - } - - return obj[key]; - }, - - setPath(obj: Record, key: string, newValue: unknown) { - if (DEBUG && key.includes('.')) { - throw new Error( - 'You attempted to set a path with a `.` in it, but Glimmer.js does not support paths with dots.' - ); - } - - obj[key] = newValue; - }, - - scheduleRevalidate, - - toBool, - - toIterator(value: unknown): Option { - if (isNativeIterable(value)) { - return NativeIterator.from(value); - } - - return null; - }, - - scheduleDestroy(destroyable, destructor) { - scheduledDestroyables.push(destroyable); - scheduledDestructors.push(destructor); - }, - - scheduleDestroyed(fn) { - scheduledFinishDestruction.push(fn); - }, - - warnIfStyleNotTrusted() { - // Do nothing - }, - - assert(test: unknown, msg: string) { - if (!test) { - throw new Error(msg); - } - }, - - deprecate(msg: string, test: unknown) { - if (!test) { - console.warn(msg); - } - }, -}); +export function setGlobalContext(scheduleRevalidate: () => void): void { + setGlobalContextVM({ + getProp(obj: Record, key: string) { + return obj[key]; + }, + + setProp(obj: Record, key: string, newValue: unknown) { + obj[key] = newValue; + }, + + getPath(obj: Record, key: string) { + if (DEBUG && key.includes('.')) { + throw new Error( + 'You attempted to get a path with a `.` in it, but Glimmer.js does not support paths with dots.' + ); + } + + return obj[key]; + }, + + setPath(obj: Record, key: string, newValue: unknown) { + if (DEBUG && key.includes('.')) { + throw new Error( + 'You attempted to set a path with a `.` in it, but Glimmer.js does not support paths with dots.' + ); + } + + obj[key] = newValue; + }, + + scheduleRevalidate, + + toBool, + + toIterator(value: unknown): Option { + if (isNativeIterable(value)) { + return NativeIterator.from(value); + } + + return null; + }, + + scheduleDestroy(destroyable, destructor) { + scheduledDestroyables.push(destroyable); + scheduledDestructors.push(destructor); + }, + + scheduleDestroyed(fn) { + scheduledFinishDestruction.push(fn); + }, + + warnIfStyleNotTrusted() { + // Do nothing + }, + + assert(test: unknown, msg: string) { + if (!test) { + throw new Error(msg); + } + }, + + deprecate(msg: string, test: unknown) { + if (!test) { + console.warn(msg); + } + }, + }); +} /** * The environment delegate base class shared by both the client and SSR diff --git a/packages/@glimmer/core/src/render-component/index.ts b/packages/@glimmer/core/src/render-component/index.ts index 6bf40e959..f5436be91 100644 --- a/packages/@glimmer/core/src/render-component/index.ts +++ b/packages/@glimmer/core/src/render-component/index.ts @@ -18,7 +18,7 @@ import { import { artifacts } from '@glimmer/program'; import { programCompilationContext } from '@glimmer/opcode-compiler'; -import { ClientEnvDelegate } from '../environment/delegates'; +import { ClientEnvDelegate, setGlobalContext } from '../environment/delegates'; import { CompileTimeResolver, RuntimeResolver } from './resolvers'; import { SimpleElement, SimpleDocument } from '@simple-dom/interface'; @@ -101,6 +101,8 @@ export function scheduleRevalidate(): void { }, 0); } +setGlobalContext(scheduleRevalidate); + function revalidate(): void { for (const result of results) { const { env } = result;