Skip to content

Instantly share code, notes, and snippets.

@isavch
Last active January 17, 2018 15:58
Show Gist options
  • Select an option

  • Save isavch/3b8f59dd91146c4e2312bb4dc431d835 to your computer and use it in GitHub Desktop.

Select an option

Save isavch/3b8f59dd91146c4e2312bb4dc431d835 to your computer and use it in GitHub Desktop.
Replay

Replay flow

Which actions should be replayed? I guess only those are modyfying data on backend like:

  • POST
  • PUT
  • DELETE

When request failed we should save it somewhere in store, I think store should look like this

{
   replays: {
      id: {
         {
            method: 'POST',
            body: { name:  5 },
            headers: {}
         }
      }
      ....
   }
}

There will be always only one action per object, let's look at examples: Offline: Create -> Update -> Online

  1. Create failed
  2. Save it into replay
  3. Update failed
  4. Only body of action should be replaced
  5. Single create action will be dispatched

Offline: Create-> Delete

  1. Create failed
  2. Delete failed
  3. Online
  4. No actions should be dispatched

Offline: Update->Delete Same as above

So idea is just push actual state, not all the actions, and keep in store only latest merged action. Also replays queue should always go first, before any request

@simpleigh
Copy link

Would it be good to structure replays in the same shape as data, i.e. arranged by root then type then object ID?

So idea is just push actual state, not all the actions, and keep in store only latest merged action.

๐Ÿ‘ store is used by app and should reflect the app's understanding of the state.

Also replays queue should always go first, before any request

๐Ÿ‘ this is a really good idea - then we know replies will sync ASAP when people are online.

@simpleigh
Copy link

I'd started thinking about request deduplication at https://github.com/27partners/redux-wp-json/issues/36. Will make a diagram of this.

@simpleigh
Copy link

What about this:

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