Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: requestDidReplay callback in background sync queue #1502

Closed
Toilal opened this issue May 28, 2018 · 1 comment
Closed

Feature Request: requestDidReplay callback in background sync queue #1502

Toilal opened this issue May 28, 2018 · 1 comment

Comments

@Toilal
Copy link

Toilal commented May 28, 2018

Library Affected:
workbox-background-sync

Browser & Platform:
"all browsers"

Feature Request Description:

This followup: #868 (comment)

I need a callback requestDidReplay invoked after each replay response to read the effective response from the API before the next request is handled.

Description of the use case

Consider a simple CRUD REST API server. The user can create an object and then modify it, regardless he is online or offline, from the webapp.

When he's online, 2 REST API calls are done, and the server generates an id on POST (first call)

POST /api/object (API server generates an id=1337)
PUT /api/object/1337

When he's offline, Service Worker and background-sync module save requests into a Queue, but the id is generated by ServiceWorker instead of API.

POST /api/object => The ServiceWorker generates a local temporary negative id=-1, and this requests is queued.
PUT /api/object/-1 => The following update request is also queued with it's temporary id.

When user is back online, those requests can be replayed, but we have to read the API server response from POST request to get the database id generated by the server, and replace it into PUT request before replaying it.

This can't be done without introducting a new requestDidReplay callback. (requestWillReplay and a global object to store ids mapping will also be used).

@jeffposnick
Copy link
Contributor

Closing this, as it should be addressed in Workbox v4. (See #1710 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants