From c8dd4f664aea3d89829ae60081748099eefd70a5 Mon Sep 17 00:00:00 2001 From: Ian <52504170+ibacher@users.noreply.github.com> Date: Fri, 12 Jul 2024 05:52:05 -0400 Subject: [PATCH] (fix) subscribeToContext should send the current value of the context on subscribe (#1080) --- packages/framework/esm-context/src/context.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/esm-context/src/context.ts b/packages/framework/esm-context/src/context.ts index 6baf0c2d2..40b734112 100644 --- a/packages/framework/esm-context/src/context.ts +++ b/packages/framework/esm-context/src/context.ts @@ -99,6 +99,9 @@ export type ContextCallback = (state: Readonly | null | un export function subscribeToContext(namespace: string, callback: ContextCallback) { let previous = getContext(namespace); + // set initial value + callback(Object.freeze(Object.assign({}, previous))); + return contextStore.subscribe((state) => { let current: Readonly | null | undefined = namespace in state ? (state[namespace] as T) : null;