You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-2
Original file line number
Diff line number
Diff line change
@@ -440,11 +440,39 @@ if(action.type === offlineActionTypes.FETCH_OFFLINE_MODE) // do something in you
440
440
SnackBars, Dialog, Popups, or simple informative text are good means of conveying to the user that the operation failed due to lack of internet connection.
441
441
442
442
### Offline Queue
443
-
A queue system to store actions that failed due to lack of connectivity. It works for both plain object actions and thunks.
444
-
It allows you to:
443
+
A queue system to store actions that failed due to lack of connectivity. It works for both plain object actions and thunks. It allows you to:
444
+
445
445
- Re-dispatch the action/thunk as soon as the internet connection is back online again
446
446
- Dismiss the action from the queue based on a different action dispatched (i.e. navigating to a different screen, the fetch action is no longer relevant)
447
447
448
+
#### Managing duplicate actions
449
+
If a similar action already exists on the queue, we remove it and push it again to the end, so it has an overriding effect.
450
+
The default criteria to detect duplicates is by using `lodash.isEqual` for plain actions and `thunk.toString()` for thunks/functions. However, you can customise the comparison function to acommodate it to your needs. For that, you need to use the factory version for your network reducer.
The comparison function receives the action dispatched when offline and the current `actionQueue`. The result of the function will be either `undefined`, meaning no match found, or the action that matches the passed in action. So basically, you need to return the upcoming action if you wish to replace an existing one. An example of how to use it can be found [here](https://github.com/rgommezz/react-native-offline/blob/master/test/reducer.test.js#L121).
468
+
469
+
```js
470
+
functioncomparisonFn(
471
+
action:ReduxAction|ReduxThunk,
472
+
actionQueue:Array<ReduxAction|ReduxThunk>,
473
+
): ?(ReduxAction | ReduxThunk)
474
+
```
475
+
448
476
#### Plain Objects
449
477
In order to configure your PO actions to interact with the offline queue you need to use the `meta` property in your actions, following [flux standard actions convention](https://github.com/acdlite/flux-standard-action#meta). They need to adhere to the below API:
0 commit comments