-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
First of all, I love the shape of this library—it’s exactly what I want for using the Context Protocol in my custom elements.
I did however notice a bug where providers can effectively only support one context (the first one that’s set with setContextValue().
I believe this is because when the event listener is added it’s keeping the context value from the first call rather than from each setContextValue() call, then it bails early when comparing with the event’s context.
context-protocol/src/subscriptions.ts
Lines 37 to 52 in 1a39b1a
| const setContextValue = <T>( | |
| /** The provider to match. */ | |
| provider: EventTarget, | |
| /** The context key to match. */ | |
| context: ExtractContext<T>, | |
| /** The data to provide. */ | |
| value: ContextType<T>, | |
| ): void => { | |
| const consumers = UPSERT(CONSUMERS_BY_PROVIDER, provider, () => { | |
| provider.addEventListener( | |
| "context-request", | |
| // @ts-expect-error while `EventTarget` listeners cannot be typed | |
| (event: ContextRequestEvent<T>) => { | |
| if (event.context !== context) return |
I might get around to a fix.
Metadata
Metadata
Assignees
Labels
No labels