Skip to content

Commit

Permalink
feat(signal): command trigger interface
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Jan 28, 2023
1 parent 3d23683 commit dda9466
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions core/signal/src/command-trigger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {signalManager} from './signal-manager.js';

import type {OmitFirstParam, Stringifyable} from '@alwatr/type';


/**
* Command trigger/request interface.
*/
export const commandTrigger = {
/**
* Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.
*
* Example:
*
* ```ts
* const returnObject = await commandTrigger.request<ArgumentType, ReturnType>('show-dialog', {foo: 'bar'});
* ```
*/
request: signalManager.requestCommand,

/**
* Bind define command to special command.
*
* Example:
*
* ```ts
* const showDialog = commandTrigger.bind<ArgumentType, ReturnType>('show-dialog');
* ```
*/
bind: <TArgument extends Record<string, Stringifyable>, TReturn extends Stringifyable>(commandId: string) =>({
/**
* Command signal Id.
*/
id: commandId,

/**
* Dispatch request command signal with commandArgument as detail and return untilNext of callback signal.
*
* Example:
*
* ```ts
* const returnObject = await showDialog.request({foo: 'bar'});
* ```
*/
request: signalManager.requestCommand.bind(null, commandId) as unknown as
OmitFirstParam<typeof signalManager.setContextProvider<TArgument, TReturn>>,
}),
} as const;

0 comments on commit dda9466

Please sign in to comment.