Skip to content

Commit

Permalink
fix(signal): requestableContextProvider.getValue
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Mar 16, 2023
1 parent b8a8e55 commit 0a7111d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/signal/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export const untilNext = <T extends Stringifyable>(signalId: string): Promise<T>
* setContextProvider('content-change', async (requestParam) => await fetchNewContent(requestParam));
* ```
*/
export const setContextProvider = <TContext extends Stringifyable, TRquest extends Stringifyable>(
export const setContextProvider = <TContext extends Stringifyable, TRquest extends Stringifyable = null>(
signalId: string,
signalProvider: ProviderFunction<TRquest, TContext | void>,
options: Partial<ProviderOptions> = {},
Expand Down
18 changes: 16 additions & 2 deletions core/signal/src/requestable-context-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {contextProvider} from './context-provider.js';
import {setContextProvider} from './core.js';
import {getDetail, setContextProvider} from './core.js';
import {RequestableContext} from './type.js';

import type {Stringifyable, OmitFirstParam} from '@alwatr/type';
Expand Down Expand Up @@ -37,9 +37,23 @@ export const requestableContextProvider = {
* const productListProvider = requestableContextProvider.bind<ProductListType>('product-list');
* ```
*/
bind: <TContextContent extends Stringifyable, TRquest extends Stringifyable>(contextId: string) =>({
bind: <TContextContent extends Stringifyable, TRquest extends Stringifyable = null>(contextId: string) =>({
...contextProvider.bind<RequestableContext<TContextContent>>(contextId),

/**
* Get context value.
*
* Example:
*
* ```ts
* const currentProductList = productListConsumer.getValue();
* TODO: update me
* ```
*/
getValue: (): RequestableContext<TContextContent> =>
getDetail<RequestableContext<TContextContent>>(contextId) ?? {state: 'initial'},


/**
* Defines the provider of the context signal that will be called when the context requested.
*
Expand Down

0 comments on commit 0a7111d

Please sign in to comment.