Skip to content

Commit 9680f4e

Browse files
rename form state into flow state
1 parent a1efb65 commit 9680f4e

4 files changed

Lines changed: 27 additions & 27 deletions

File tree

packages/example/src/FlowNavigatorExample.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ export const FlowNavigatorExample = () => {
3535
);
3636
}
3737

38-
const initialFormState = {
38+
const initialFlowState = {
3939
myValue31: false,
4040
myValue4: hasToPassStep4,
4141
};
4242

43-
type FormState = typeof initialFormState;
43+
type FlowState = typeof initialFlowState;
4444

4545
const config = {
46-
Step31: (formState: FormState) => formState.myValue31,
47-
Step4: (formState: FormState) => formState.myValue4,
46+
Step31: (flowState: FlowState) => flowState.myValue31,
47+
Step4: (flowState: FlowState) => flowState.myValue4,
4848
};
4949

5050
return (
5151
<FlowNavigator.Navigator
5252
screenOptions={{headerShown: false}}
5353
config={config}
54-
initialFormState={initialFormState}>
54+
initialFlowState={initialFlowState}>
5555
<FlowNavigator.Screen name="Step1" component={Step1Page} />
5656
<FlowNavigator.Screen name="Step2" component={Step2Navigator} />
5757
<FlowNavigator.Group>

packages/lib/src/navigators/createFlowNavigator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function FlowNavigator({
3030
screenListeners,
3131
screenOptions,
3232
config,
33-
initialFormState,
33+
initialFlowState,
3434
...rest
3535
}: FlowNavigatorProps) {
3636
const parentNavigation = useNavigation();
@@ -46,7 +46,7 @@ function FlowNavigator({
4646
FlowActionHelpers<ParamListBase>,
4747
FlowNavigationOptions,
4848
FlowNavigationEventMap
49-
>(buildFlowRouter(quitFlow, { config, initialFormState }), {
49+
>(buildFlowRouter(quitFlow, { config, initialFlowState }), {
5050
id,
5151
initialRouteName,
5252
children,

packages/lib/src/routers/FlowRouter.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import {
77
StackRouter,
88
StackRouterOptions,
99
} from "@react-navigation/native";
10-
import { Config, FlowNavigationState, FormState } from "../types/types";
10+
import { Config, FlowNavigationState, FlowState } from "../types/types";
1111

1212
export type FlowRouterOptions = StackRouterOptions;
1313

1414
export type FlowActionHelpers<ParamList extends ParamListBase> = {
1515
goToNextStep(): void;
1616
goToPreviousStep(): void;
1717
quitFlow(): void;
18-
setStoreState(formState: FormState): void;
18+
setStoreState(flowState: FlowState): void;
1919
} & StackActionHelpers<ParamList>;
2020

2121
export type FlowActionType =
@@ -35,16 +35,16 @@ export type FlowActionType =
3535
| {
3636
type: "SET_STORE_STATE";
3737
source?: string;
38-
payload: { formState: Object };
38+
payload: { flowState: Object };
3939
};
4040

4141
export const buildFlowRouter =
4242
(
4343
quitFlowHelper: () => void,
4444
{
4545
config,
46-
initialFormState,
47-
}: { config: Config<ParamListBase>; initialFormState: FormState }
46+
initialFlowState,
47+
}: { config: Config<ParamListBase>; initialFlowState: FlowState }
4848
) =>
4949
(
5050
options: FlowRouterOptions
@@ -65,7 +65,7 @@ export const buildFlowRouter =
6565

6666
const disabledRouteNames = Object.entries(config)
6767
.filter(([_, isRouteNameEnabledCb]) => {
68-
return !isRouteNameEnabledCb(initialFormState);
68+
return !isRouteNameEnabledCb(initialFlowState);
6969
})
7070
.map(([routeName]) => routeName);
7171

@@ -79,7 +79,7 @@ export const buildFlowRouter =
7979
return {
8080
...router.getInitialState(params),
8181
availableRoutes,
82-
formState: initialFormState,
82+
flowState: initialFlowState,
8383
};
8484
},
8585

@@ -130,14 +130,14 @@ export const buildFlowRouter =
130130
return state;
131131

132132
case "SET_STORE_STATE":
133-
const newFormState = {
134-
...state.formState,
135-
...action.payload.formState,
133+
const newFlowState = {
134+
...state.flowState,
135+
...action.payload.flowState,
136136
};
137137

138138
const disabledRouteNames = Object.entries(config)
139139
.filter(([_, isRouteNameEnabledCb]) => {
140-
return !isRouteNameEnabledCb(newFormState);
140+
return !isRouteNameEnabledCb(newFlowState);
141141
})
142142
.map(([routeName]) => routeName);
143143

@@ -162,9 +162,9 @@ export const buildFlowRouter =
162162

163163
return {
164164
...state,
165-
formState: {
166-
...state.formState,
167-
...action.payload.formState,
165+
flowState: {
166+
...state.flowState,
167+
...action.payload.flowState,
168168
},
169169
index: state.index - builtRemovedRoute.length,
170170
availableRoutes,
@@ -186,8 +186,8 @@ export const buildFlowRouter =
186186
quitFlow: () => {
187187
return { type: "QUIT_FLOW" };
188188
},
189-
setStoreState: (formState) => {
190-
return { type: "SET_STORE_STATE", payload: { formState } };
189+
setStoreState: (flowState) => {
190+
return { type: "SET_STORE_STATE", payload: { flowState } };
191191
},
192192
},
193193
};

packages/lib/src/types/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ export type FlowNavigationProp<
4444
export type FlowNavigationState<ParamList extends ParamListBase> =
4545
NavigationState<ParamList> & {
4646
availableRoutes: Extract<keyof ParamList, string>[];
47-
formState: FormState;
47+
flowState: FlowState;
4848
// type: "flow"; : TODO add flow type and key
4949
};
5050

5151
export type Config<ParamList = ParamListBase> = {
52-
[k in Partial<keyof ParamList>]: (formState: FormState) => boolean;
52+
[k in Partial<keyof ParamList>]: (flowState: FlowState) => boolean;
5353
};
5454

55-
export type FormState = Object;
55+
export type FlowState = Object;
5656

5757
export type FlowNavigatorProps = DefaultNavigatorOptions<
5858
ParamListBase,
@@ -63,7 +63,7 @@ export type FlowNavigatorProps = DefaultNavigatorOptions<
6363
StackRouterOptions &
6464
NativeStackNavigationConfig & {
6565
config: Config<ParamListBase>;
66-
initialFormState: FormState;
66+
initialFlowState: FlowState;
6767
};
6868

6969
export type FlowStackNavigationOptions = NativeStackNavigationOptions & {

0 commit comments

Comments
 (0)