Create Action
#
ParametersName | Required | Type | Description |
---|---|---|---|
Settings | true | Settings | Action settings object |
createAction({ key: 'data', name: 'ACTION_NAME',})
#
Settings#
nameType | Default | Required | Description |
---|---|---|---|
String | - | Yes | The action name. |
#
keyType | Default | Required | Description |
---|---|---|---|
String | - | No | The name of the key in which the data will be stored |
#
keysType | Default | Required | Description |
---|---|---|---|
String | - | No | Stored data key when need find nested key |
#
forceUpdateType | Default | Required | Description |
---|---|---|---|
Boolean | - | No | ---- |
#
persistsType | Default | Required | Description |
---|---|---|---|
Boolean | false | No | Stores data from store to localStorage on web and asyncStorage on mobile |
#
apiCallType | 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 |
#
mergecreateAction({ // ...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 |
#
reuducerIf you need control reducer yourself you can use this method
#
ParametersName | 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 } } } })
#
handleResponseIf you need parse api call response manually. The return value of this function will be stored in store.
#
ParametersName | Required | Type | Description |
---|---|---|---|
data | true | any | Api call response |
createAction({ // ...other options handleResponse: (data) => { // your code here return //.... } })
#
onSuccessThis function calls every time after a successful response
#
ParametersName | Required | Type | Description |
---|---|---|---|
data | false | EventArguments | Event arguments result and dispatch |
createAction({ // ...other options onSuccess: ({ result, dispatch }) => { // ... do something here } })
#
onErrorThis function calls every time after a error response
#
ParametersName | Required | Type | Description |
---|---|---|---|
data | false | EventArguments | Event arguments result and dispatch |
createAction({ // ...other options onError: ({ result, dispatch }) => { // ... do something here } })
#
Methods#
restoreCall action and restore your data and set default value
yourAction.restore()
#
delay#
ParametersName | Required | Type | Description |
---|---|---|---|
duration | true | number | Delay duration |
yourAction.delay(1000)
// if you need call with other argumentsyourAction.delay(1000, arg1, arg2, /* ... */)
#
settings#
ParametersName | Required | Type | Description |
---|---|---|---|
- | true | ActionSettings | Before call action you can change action settings |
const updatedParamsAction = yourAction.settings({ // set any settings what you need})
updatedParamsAction()