@flowerforce/flower-react 4.0.8-beta.0 → 4.0.10-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
@@ -44,6 +44,10 @@ yarn add @flowerforce/flower-react
|
|
44
44
|
|
45
45
|
## Configuration
|
46
46
|
|
47
|
+
|
48
|
+
Flower React works with redux global state.
|
49
|
+
|
50
|
+
If you starts an application with Flower React from scratch, you need to wrap your application with **FlowerProvider**
|
47
51
|
The **FlowerProvider** component wraps the entire application, providing a global redux context to manage the application flow.
|
48
52
|
|
49
53
|
```jsx
|
@@ -58,39 +62,70 @@ function Root() {
|
|
58
62
|
)
|
59
63
|
}
|
60
64
|
```
|
61
|
-
|
62
|
-
|
65
|
+
|
66
|
+
If your application is already built with redux as global state manager, you can use differents approaches:
|
67
|
+
|
68
|
+
- Separates Providers
|
69
|
+
|
70
|
+
In this case, you need to wrap your application with the **FlowerProvider** component in addition to the classic Redux provider.
|
71
|
+
The order of providers is not relevant, since their redux contexts are different.
|
72
|
+
n.b.: FlowerProvider generates a store instance with `FlowerData slice` from `flower-react-form`
|
73
|
+
|
63
74
|
```jsx
|
64
75
|
import React from 'react'
|
65
|
-
import {
|
66
|
-
import {
|
67
|
-
|
68
|
-
const reducers = {
|
69
|
-
customReducer: customReducer.reducer,
|
70
|
-
customReducer2: customReducer2.reducer
|
71
|
-
}
|
76
|
+
import { Provider } from 'react-redux'
|
77
|
+
import { yourStore } from 'yourStore'
|
78
|
+
import { FlowerProvider } from '@flowerforce/flower-react'
|
72
79
|
|
73
80
|
function Root() {
|
74
81
|
return (
|
75
|
-
<
|
76
|
-
<
|
77
|
-
|
82
|
+
<Provider store={yourStore}>
|
83
|
+
<FlowerProvider>
|
84
|
+
<App />
|
85
|
+
</FlowerProvider>
|
86
|
+
</Provider>
|
78
87
|
)
|
79
88
|
}
|
80
89
|
```
|
81
|
-
|
90
|
+
|
91
|
+
- Single Provider
|
92
|
+
|
93
|
+
For this scenario, we provides ***createStoreWithFlower***
|
94
|
+
This functions takes a `configureStoreOptions` object (same as createStore from redux) and an optional `middlewaresBlacklist`, since flower inject automatically some middlewares in its store.
|
95
|
+
To generate slices fully compatible, you can use ***createSliceWithFlower***, a function same as `createSlice` from redux.
|
96
|
+
Let's see the needed configuration
|
82
97
|
```jsx
|
83
98
|
import React from 'react'
|
84
|
-
import {
|
99
|
+
import { Provider } from 'react-redux'
|
100
|
+
import { FormProvider, createStoreWithFlower, createSliceWithFlower } from '@flowerforce/flower-react'
|
101
|
+
|
102
|
+
const myStoreWithFlower = createSliceWithFlower({
|
103
|
+
name: 'myStore',
|
104
|
+
initialData: {},
|
105
|
+
reducers: {
|
106
|
+
add: (state) => {
|
107
|
+
state.count += 1
|
108
|
+
}
|
109
|
+
}
|
110
|
+
})
|
111
|
+
|
112
|
+
const storeWithFlower = createStoreWithFlower({
|
113
|
+
reducer: {
|
114
|
+
myStore: myStoreWithFlower.reducer,
|
115
|
+
}
|
116
|
+
})
|
85
117
|
|
86
118
|
function Root() {
|
87
119
|
return (
|
88
|
-
<
|
120
|
+
<Provider store={storeWithFlower}>
|
89
121
|
<App />
|
90
|
-
</
|
122
|
+
</Provider>
|
91
123
|
)
|
92
124
|
}
|
93
125
|
```
|
126
|
+
|
127
|
+
In this scenario, we need a single provider, so we use the default redux provider
|
128
|
+
|
94
129
|
## How to use
|
95
130
|
|
96
131
|
### Simple Example
|
@@ -621,11 +656,9 @@ import {
|
|
621
656
|
Flower,
|
622
657
|
FlowerRoute,
|
623
658
|
FlowerNavigate,
|
624
|
-
FlowerNode
|
625
|
-
FlowerField,
|
659
|
+
FlowerNode
|
626
660
|
} from '@flowerforce/flower-react'
|
627
661
|
|
628
|
-
|
629
662
|
import {
|
630
663
|
FlowerField,
|
631
664
|
} from '@flowerforce/flower-react-form'
|
@@ -984,3 +1017,4 @@ The Flower React docs are published at [flowerjs.it/](https://flowerjs.it)
|
|
984
1017
|
|
985
1018
|
|
986
1019
|
|
1020
|
+
|
package/dist/index.cjs.js
CHANGED
@@ -281,7 +281,7 @@ component$6.displayName = 'FlowerFlow';
|
|
281
281
|
const FlowerFlow = component$6;
|
282
282
|
|
283
283
|
const ACTION_TYPES = {
|
284
|
-
back: ['
|
284
|
+
back: ['back', 'prevToNode'],
|
285
285
|
jump: ['node', 'node'],
|
286
286
|
next: ['next', 'next'],
|
287
287
|
restart: ['restart', 'restart'],
|
@@ -306,11 +306,12 @@ const makeActionPayload = (actions, keys) => (flowName, params) => {
|
|
306
306
|
payload
|
307
307
|
};
|
308
308
|
};
|
309
|
-
const
|
309
|
+
const makeActionPayloadOnBack = makeActionPayload(ACTION_TYPES.back, PAYLOAD_KEYS_NEEDED.back);
|
310
310
|
const makeActionPayloadOnReset = makeActionPayload(ACTION_TYPES.reset, PAYLOAD_KEYS_NEEDED.reset);
|
311
311
|
const makeActionPayloadOnNode = makeActionPayload(ACTION_TYPES.jump, PAYLOAD_KEYS_NEEDED.jump);
|
312
312
|
const makeActionPayloadOnNext = makeActionPayload(ACTION_TYPES.next, PAYLOAD_KEYS_NEEDED.next);
|
313
313
|
const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLOAD_KEYS_NEEDED.restart);
|
314
|
+
|
314
315
|
/** This hook allows you to read flow informations, such as the flowName and ID of the current node.
|
315
316
|
*
|
316
317
|
* It also exposes all the functions to navigate within the flow:
|
@@ -330,10 +331,8 @@ const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLO
|
|
330
331
|
* @param {string} name - optional parameter, if flowName exist, name is not used
|
331
332
|
*/
|
332
333
|
const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
333
|
-
const { store, useSelector, dispatch } = flowerReactStore.ReduxFlowerProvider.getReduxHooks();
|
334
|
-
// const dispatch = useDispatch()
|
335
334
|
const { name: flowNameDefault, initialData } = React.useContext(flowerReactContext.FlowerReactContext);
|
336
|
-
|
335
|
+
const { store, dispatch, useSelector } = flowerReactStore.ReduxFlowerProvider.getReduxHooks();
|
337
336
|
const flowName = (customFlowName || name || flowNameDefault);
|
338
337
|
const nodeId = useSelector(makeSelectCurrentNodeId(flowName ?? ''));
|
339
338
|
const startId = useSelector(makeSelectStartNodeId(flowName ?? ''));
|
@@ -366,7 +365,7 @@ const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
|
366
365
|
emitNavigateEvent({ type, payload });
|
367
366
|
}, [dispatch, emitNavigateEvent, flowName, store]);
|
368
367
|
const back = React.useCallback((param) => {
|
369
|
-
const { type, payload } =
|
368
|
+
const { type, payload } = makeActionPayloadOnBack(flowName, param);
|
370
369
|
dispatch({ type: `${flowerCore.REDUCER_NAME.FLOWER_FLOW}/${type}`, payload });
|
371
370
|
emitNavigateEvent({ type, payload });
|
372
371
|
}, [dispatch, emitNavigateEvent, flowName]);
|
@@ -627,15 +626,6 @@ const createStoreWithFlower = (configureStore, middlewaresBlacklist) => {
|
|
627
626
|
});
|
628
627
|
};
|
629
628
|
|
630
|
-
// createSlice({
|
631
|
-
// name: "myStore",
|
632
|
-
// initialState: {
|
633
|
-
// gino: 1,
|
634
|
-
// } as Record<string, number>,
|
635
|
-
// reducers: {
|
636
|
-
// add: (state) => ({ ...state, gino: state.gino + 1 }),
|
637
|
-
// },
|
638
|
-
// });
|
639
629
|
const updateAction = (reducerName) => toolkit.createAction(`${reducerName}/flowerUpdateData`);
|
640
630
|
const createSliceWithFlower = (createSliceOptions) => {
|
641
631
|
const { name, reducers } = createSliceOptions;
|
package/dist/index.esm.js
CHANGED
@@ -280,7 +280,7 @@ component$6.displayName = 'FlowerFlow';
|
|
280
280
|
const FlowerFlow = component$6;
|
281
281
|
|
282
282
|
const ACTION_TYPES = {
|
283
|
-
back: ['
|
283
|
+
back: ['back', 'prevToNode'],
|
284
284
|
jump: ['node', 'node'],
|
285
285
|
next: ['next', 'next'],
|
286
286
|
restart: ['restart', 'restart'],
|
@@ -305,11 +305,12 @@ const makeActionPayload = (actions, keys) => (flowName, params) => {
|
|
305
305
|
payload
|
306
306
|
};
|
307
307
|
};
|
308
|
-
const
|
308
|
+
const makeActionPayloadOnBack = makeActionPayload(ACTION_TYPES.back, PAYLOAD_KEYS_NEEDED.back);
|
309
309
|
const makeActionPayloadOnReset = makeActionPayload(ACTION_TYPES.reset, PAYLOAD_KEYS_NEEDED.reset);
|
310
310
|
const makeActionPayloadOnNode = makeActionPayload(ACTION_TYPES.jump, PAYLOAD_KEYS_NEEDED.jump);
|
311
311
|
const makeActionPayloadOnNext = makeActionPayload(ACTION_TYPES.next, PAYLOAD_KEYS_NEEDED.next);
|
312
312
|
const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLOAD_KEYS_NEEDED.restart);
|
313
|
+
|
313
314
|
/** This hook allows you to read flow informations, such as the flowName and ID of the current node.
|
314
315
|
*
|
315
316
|
* It also exposes all the functions to navigate within the flow:
|
@@ -329,10 +330,8 @@ const makeActionPayloadOnRestart = makeActionPayload(ACTION_TYPES.restart, PAYLO
|
|
329
330
|
* @param {string} name - optional parameter, if flowName exist, name is not used
|
330
331
|
*/
|
331
332
|
const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
332
|
-
const { store, useSelector, dispatch } = ReduxFlowerProvider.getReduxHooks();
|
333
|
-
// const dispatch = useDispatch()
|
334
333
|
const { name: flowNameDefault, initialData } = useContext(FlowerReactContext);
|
335
|
-
|
334
|
+
const { store, dispatch, useSelector } = ReduxFlowerProvider.getReduxHooks();
|
336
335
|
const flowName = (customFlowName || name || flowNameDefault);
|
337
336
|
const nodeId = useSelector(makeSelectCurrentNodeId(flowName ?? ''));
|
338
337
|
const startId = useSelector(makeSelectStartNodeId(flowName ?? ''));
|
@@ -365,7 +364,7 @@ const useFlower = ({ flowName: customFlowName, name } = {}) => {
|
|
365
364
|
emitNavigateEvent({ type, payload });
|
366
365
|
}, [dispatch, emitNavigateEvent, flowName, store]);
|
367
366
|
const back = useCallback((param) => {
|
368
|
-
const { type, payload } =
|
367
|
+
const { type, payload } = makeActionPayloadOnBack(flowName, param);
|
369
368
|
dispatch({ type: `${REDUCER_NAME.FLOWER_FLOW}/${type}`, payload });
|
370
369
|
emitNavigateEvent({ type, payload });
|
371
370
|
}, [dispatch, emitNavigateEvent, flowName]);
|
@@ -626,15 +625,6 @@ const createStoreWithFlower = (configureStore$1, middlewaresBlacklist) => {
|
|
626
625
|
});
|
627
626
|
};
|
628
627
|
|
629
|
-
// createSlice({
|
630
|
-
// name: "myStore",
|
631
|
-
// initialState: {
|
632
|
-
// gino: 1,
|
633
|
-
// } as Record<string, number>,
|
634
|
-
// reducers: {
|
635
|
-
// add: (state) => ({ ...state, gino: state.gino + 1 }),
|
636
|
-
// },
|
637
|
-
// });
|
638
628
|
const updateAction = (reducerName) => createAction(`${reducerName}/flowerUpdateData`);
|
639
629
|
const createSliceWithFlower = (createSliceOptions) => {
|
640
630
|
const { name, reducers } = createSliceOptions;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@flowerforce/flower-react",
|
3
|
-
"version": "4.0.
|
3
|
+
"version": "4.0.10-beta.0",
|
4
4
|
"description": "FlowerJS components, hooks and utils for React.",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -37,10 +37,10 @@
|
|
37
37
|
"typescript": "^5.4.5"
|
38
38
|
},
|
39
39
|
"dependencies": {
|
40
|
-
"@flowerforce/flower-core": "4.0.1-beta.
|
41
|
-
"@flowerforce/flower-react-context": "4.0.1-beta.
|
42
|
-
"@flowerforce/flower-react-store": "4.0.1-beta.
|
43
|
-
"@flowerforce/flower-react-shared": "4.0.6-beta.
|
40
|
+
"@flowerforce/flower-core": "4.0.1-beta.7",
|
41
|
+
"@flowerforce/flower-react-context": "4.0.1-beta.7",
|
42
|
+
"@flowerforce/flower-react-store": "4.0.1-beta.7",
|
43
|
+
"@flowerforce/flower-react-shared": "4.0.6-beta.3",
|
44
44
|
"lodash": "^4.17.21"
|
45
45
|
},
|
46
46
|
"exports": {
|