Skip to content

Commit

Permalink
fix: set default value of context if undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
ryu-man committed Jul 23, 2023
1 parent 0ffe9c1 commit 4c51ce1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/context/sharedContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export type SharedContext<T> = Record<string, Record<string, unknown>> & T;
export function getSharedContext<T>(key?: 'input' | 'label'): Readable<SharedContext<T>> {
const context$ = getContext(SVELTE_FUI_SHARED_CONTEXT_KEY) as Writable<SharedContext<T>>;

if (!context$) {
return readonly(writable({} as SharedContext<T>));
}

if (key) {
return derived(context$, (val) => val[key] as SharedContext<T>);
}
Expand Down

0 comments on commit 4c51ce1

Please sign in to comment.