Skip to content

Commit

Permalink
feat(signal): new requestable context consumer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Jan 28, 2023
1 parent 2c8d576 commit bf6845f
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions core/signal/src/requestable-context-consumer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {Stringifyable, OmitFirstParam} from '@alwatr/type';

import {contextConsumer} from './context-consumer.js';
import {signalManager} from './signal-manager.js';

/**
* Requestable context consumer interface.
*/
export const requestableContextConsumer = {
...contextConsumer,

/**
* Send new context request to the provider.
*
* Example:
*
* ```ts
* requestableContextConsumer.requestContext<RequestParamType>('product-list', {foo: 'bar'});
* const newProductList = await requestableContextConsumer.untilChange<ProductListType>('product-list');
* ```
*/
request: signalManager.requestContext,

/**
* Bind this interface to special context.
*
* Example:
*
* ```ts
* const productListConsumer = requestableContextConsumer.bind<ProductListType>('product-list');
* ```
*/
bind: <TContext extends Stringifyable, TRquest extends Stringifyable>(contextId: string) =>({
...contextConsumer.bind<TContext>(contextId),

/**
* Send new context request to the provider.
*
* Example:
*
* ```ts
* productListConsumer.requestContext({foo: 'bar'});
* const newProductList = await productListConsumer.untilChange();
* ```
*/
request: signalManager.requestContext as
OmitFirstParam<typeof signalManager.requestContext<TRquest>>,
} as const),
} as const;

0 comments on commit bf6845f

Please sign in to comment.