1

I'm trying to work out the best way to get Redux Offline to debounce server requests.

Currently when the server is busy, it saves them up in a queue and sends all of them. I'd like it just to save the last one but use the same Save action to update the redux store.

My code in the action is:

export class SaveSession extends OfflineAction<SessionTypes> {
    public readonly type = SessionTypes.SAVE_SESSION;

    constructor(public session: ISession) {
        super();

        this.meta = {
            offline: {
                effect: {
                    url: `${process.env.REACT_APP_API}/api/session/save`,
                    body: JSON.stringify(session),
                    method: 'POST',
                    headers: authHeader()
                },
                commit: new SaveSessionSuccess(),
                rollback: new SaveSessionError()
            }
        };
    }
}

I'm looking through the documentation but I can't see anything around debouncing server requests.

Is this possible?

beek
  • 3,522
  • 8
  • 33
  • 86

1 Answers1

0

Have a look at this link from the documentation.

It seems like you will be interested in overriding the enqueue function to adjust the logic to suit your need: some kind of smart queue.

They said they've come up with smart-queue to serve this purpose: check this. Check it out and roll out the mechanism to match your requirement.

Ravi
  • 141
  • 5