Skip to content

Commit

Permalink
Merge pull request #26 from Trent-Evernote/growth/trent/EG-1320-3
Browse files Browse the repository at this point in the history
Added flow options argument to onWillChooseFlow function call
  • Loading branch information
hadleyac-en authored Feb 4, 2022
2 parents c42331e + 6a3d8c6 commit 8715781
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aquaman-redux",
"version": "1.2.3",
"version": "1.3.0",
"description": "Redux middlewear for composable, declarative control flow",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
12 changes: 9 additions & 3 deletions src/FlowStarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import flowController, {
AQUAMAN_LOCATION_ID,
} from "./DispatchController";

import { FlowObj, MapReduxToConfig, AquamanConfig, OnWillChooseFlowReturn } from "./Types";
import { FlowObj, MapReduxToConfig, AquamanConfig, OnWillChooseFlowReturn, FlowTriggerType } from "./Types";
import { Excluder, FlowExcluder } from "./FlowExcluder";

const defaultReduxConfig = {
Expand Down Expand Up @@ -97,7 +97,10 @@ export class FlowStarter {
const canStartFlow = flow.condition && flow.condition(...states);

if (canStartFlow) {
const returnDataOrFlowObj = this.config.onWillChooseFlow(flow);
const flowOptions = {
triggerType: FlowTriggerType.Conditions
};
const returnDataOrFlowObj = this.config.onWillChooseFlow(flow, flowOptions);

const onWillChooseFlowReturn = ((): OnWillChooseFlowReturn => {
if (typeof returnDataOrFlowObj == 'object' && returnDataOrFlowObj != null) {
Expand Down Expand Up @@ -141,7 +144,10 @@ export class FlowStarter {
return;
}

const returnDataOrFlowObj = this.config.onWillChooseFlow(forcedFlow);
const flowOptions = {
triggerType: FlowTriggerType.ForceFlow
};
const returnDataOrFlowObj = this.config.onWillChooseFlow(forcedFlow, flowOptions);

const onWillChooseFlowReturn = ((): OnWillChooseFlowReturn => {
if (typeof returnDataOrFlowObj == 'object' && returnDataOrFlowObj != null) {
Expand Down
14 changes: 13 additions & 1 deletion src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@ export interface OnWillChooseFlowReturn {
preventFlowStart?: boolean,
}

export enum FlowTriggerType {
Conditions = 'Conditions',
ForceFlow = 'ForceFlow',
}

export interface FlowOptions {
triggerType: FlowTriggerType;
}

type OnWillChooseFlow = (flow: FlowObj) => OnWillChooseFlowReturn | FlowObj | false | void;
type OnWillChooseFlowWithOptions = (flow: FlowObj, flowOptions: FlowOptions) => OnWillChooseFlowReturn | FlowObj | false | void;

export interface AquamanConfig {
persistSettings?: PersistSettings;
onEndFlow: (flowId: string) => Promise<void>;
onStep: (flowId: string, stepCount: number) => void;
shouldStartFlow: (flowId: string) => boolean | void;
onWillChooseFlow: (flow: FlowObj) => OnWillChooseFlowReturn | FlowObj | false | void;
onWillChooseFlow: OnWillChooseFlow | OnWillChooseFlowWithOptions;
functionMap: { [functionName: string]: Function };
mutuallyExclusiveFlows?: string[][];
}
Expand Down

0 comments on commit 8715781

Please sign in to comment.