Skip to content
Permalink
Browse files

Toggle whether promises are returned in config

  • Loading branch information...
wacii authored and sorodrigo committed Feb 19, 2018
1 parent 9dc4f5a commit cd7e9ee2339b4d588910f9399cbbb63b73e6e6d6
Showing with 13 additions and 5 deletions.
  1. +4 −1 README.md
  2. +6 −2 src/__tests__/middleware.js
  3. +2 −1 src/defaults/index.js
  4. +1 −1 src/middleware.js
@@ -318,7 +318,8 @@ export type Config = {
enqueue: (outbox: Array<OfflineAction>, action: OfflineAction) => Array<OfflineAction>,
dequeue: (outbox: Array<OfflineAction>, action: OfflineAction) => Array<OfflineAction>,
peek: (outbox: Array<OfflineAction>) => OfflineAction
}
},
returnPromises: boolean
};
```
@@ -534,6 +535,8 @@ const config = {
`store.dispatch()` returns a promise that you can use to chain behavior off offline actions, but be careful! A chief benefit of this library is that requests are tried across sessions, but promises do not last that long. So if you use this feature, know that your promise might not get resolved, even if the associated request is eventually delivered.
> You must opt-in to this feature by setting `offlineConfig.returnPromises = true`.
#### Synchronise my state while the app is not open
Background sync is not yet supported. Coming soon.
@@ -144,8 +144,13 @@ describe('on OFFLINE_SCHEDULE_RETRY', () => {
});

describe('offlineActionTracker integration', () => {
let config, store, next;
beforeEach(() => {
({ config, store, next } = setup())
config = { ...config, returnPromises: true };
});

test('returns a promise that can be resolved', () => {
const { config, store, next } = setup();
const promise = createOfflineMiddleware(config)(store)(next)(offlineAction);

const transaction = 0;
@@ -157,7 +162,6 @@ describe('offlineActionTracker integration', () => {
});

test('returns a promise that can be rejected', () => {
const { config, store, next, action } = setup();
const promise = createOfflineMiddleware(config)(store)(next)(offlineAction);

const transaction = 0;
@@ -20,5 +20,6 @@ export default {
defaultRollback,
persistAutoRehydrate,
offlineStateLens,
queue
queue,
returnPromises: false
};
@@ -47,5 +47,5 @@ export const createOfflineMiddleware = (config: Config) => (store: any) => (
send(offlineAction, store.dispatch, config, offline.retryCount);
}

return promise || result;
return config.returnPromises ? promise || result : result;
};

0 comments on commit cd7e9ee

Please sign in to comment.
You can’t perform that action at this time.