Create Action
Parameters#
| Name | Required | Type | Description |
|---|---|---|---|
| Settings | true | Settings | Action settings object |
createAction({ key: 'data', name: 'ACTION_NAME',}) Settings#
name#
| Type | Default | Required | Description |
|---|---|---|---|
| String | - | Yes | The action name. |
key#
| Type | Default | Required | Description |
|---|---|---|---|
| String | - | No | The name of the key in which the data will be stored |
keys#
| Type | Default | Required | Description |
|---|---|---|---|
| String | - | No | Stored data key when need find nested key |
forceUpdate#
| Type | Default | Required | Description |
|---|---|---|---|
| Boolean | - | No | ---- |
persists#
| Type | Default | Required | Description |
|---|---|---|---|
| Boolean | false | No | Stores data from store to localStorage on web and asyncStorage on mobile |
apiCall#
| Type | Default | Required | Description |
|---|---|---|---|
| Function | - | No | This is an API call function, that returns a Promise (required). If you want to update the store without a request to the server you can skip this property |
merge#
createAction({ // ...other options merge: (...args) => { // your api call arguments goes here `args` return // your logic here } })| Type | Default | Required | Description |
|---|---|---|---|
| Function | - | No | This function return boolean and if it true after every call will be override existing data |
reuducer#
If you need control reducer yourself you can use this method
Parameters#
| Name | Required | Type | Description |
|---|---|---|---|
| state | true | Object | State object |
| action | true | Action | Action object |
createAction({ // ...other options key: 'yourKey', reducer: (state, action) => { return { ...state, yourKey: { ...state.yourKey, ...action.data } } } })handleResponse#
If you need parse api call response manually. The return value of this function will be stored in store.
Parameters#
| Name | Required | Type | Description |
|---|---|---|---|
| data | true | any | Api call response |
createAction({ // ...other options handleResponse: (data) => { // your code here return //.... } })onSuccess#
This function calls every time after a successful response
Parameters#
| Name | Required | Type | Description |
|---|---|---|---|
| data | false | EventArguments | Event arguments result and dispatch |
createAction({ // ...other options onSuccess: ({ result, dispatch }) => { // ... do something here } })onError#
This function calls every time after a error response
Parameters#
| Name | Required | Type | Description |
|---|---|---|---|
| data | false | EventArguments | Event arguments result and dispatch |
createAction({ // ...other options onError: ({ result, dispatch }) => { // ... do something here } })Methods#
restore#
Call action and restore your data and set default value
yourAction.restore()delay#
Parameters#
| Name | Required | Type | Description |
|---|---|---|---|
| duration | true | number | Delay duration |
yourAction.delay(1000)
// if you need call with other argumentsyourAction.delay(1000, arg1, arg2, /* ... */)settings#
Parameters#
| Name | Required | Type | Description |
|---|---|---|---|
| - | true | ActionSettings | Before call action you can change action settings |
const updatedParamsAction = yourAction.settings({ // set any settings what you need})
updatedParamsAction()