Skip to content

Commit

Permalink
(fix) subscribeToContext should send the current value of the context…
Browse files Browse the repository at this point in the history
… on subscribe (openmrs#1080)
  • Loading branch information
ibacher authored Jul 12, 2024
1 parent cea9a99 commit c8dd4f6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/framework/esm-context/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export type ContextCallback<T extends {} = {}> = (state: Readonly<T> | null | un
export function subscribeToContext<T extends {} = {}>(namespace: string, callback: ContextCallback<T>) {
let previous = getContext<T>(namespace);

// set initial value
callback(Object.freeze(Object.assign({}, previous)));

return contextStore.subscribe((state) => {
let current: Readonly<T> | null | undefined = namespace in state ? (state[namespace] as T) : null;

Expand Down

0 comments on commit c8dd4f6

Please sign in to comment.