Skip to content

Commit

Permalink
feat(interceptors): add dispatch/dispatchNow() helper interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed May 2, 2018
1 parent 5a6ce27 commit 6748515
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/interceptors/src/interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import {
setIn,
updateIn
} from "@thi.ng/paths";

import {
Event,
FX_CANCEL,
FX_DISPATCH,
FX_DISPATCH_NOW,
FX_STATE,
InterceptorFn,
InterceptorPredicate
} from "./api";


/**
* Debug interceptor to log the current event to the console.
*/
Expand All @@ -30,6 +32,24 @@ export function forwardSideFx(fxID: string): InterceptorFn {
return (_, [__, body]) => ({ [fxID]: body });
}

/**
* Higher-order interceptor. Returns interceptor which assigns given
* event to `FX_DISPATCH` side effect.
*
* @param event
*/
export const dispatch = (event: Event): InterceptorFn =>
() => ({ [FX_DISPATCH]: event });

/**
* Higher-order interceptor. Returns interceptor which assigns given
* event to `FX_DISPATCH_NOW` side effect.
*
* @param event
*/
export const dispatchNow = (event: Event): InterceptorFn =>
() => ({ [FX_DISPATCH_NOW]: event });

/**
* Higher-order interceptor. Returns interceptor which calls
* `ctx[id].record()`, where `ctx` is the currently active
Expand Down

0 comments on commit 6748515

Please sign in to comment.