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

Define state machines for redux async thunks #727

Open
acelaya opened this issue Nov 6, 2022 · 0 comments
Open

Define state machines for redux async thunks #727

acelaya opened this issue Nov 6, 2022 · 0 comments
Labels
enhancement New feature or request tech-debt

Comments

@acelaya
Copy link
Member

acelaya commented Nov 6, 2022

Currently there are some reducers containing async thunks which models look similar to this:

interface SomeStateModel {
    foo?: SomeResult;
    loading: boolean;
    error: boolean;
    errorData?: ProblemDetailsError;
}

This interfaces combines the three possible async thunk states:

Pending:

interface SomeStateModelPending {
    loading: true;
    error: false;
}

Rejected:

interface SomeStateModelRejected {
    loading: false;
    error: true;
    errorData: ProblemDetailsError;
}

Fulfilled:

interface SomeStateModelFulfilled {
    foo: SomeResult;
    loading: false;
    error: false;
}

It would be ideal to try to define the state as a union of the three above, and ensure proper type narrowing on every reducer case.

In the best case scenario, it should also be possible to narrow the types when consuming the state inside a component.


There also another use case, for actions which do not "happen" right away (like loading data), but have a "waiting" initial state, until the user actively performs an action (like saving on a form).

interface SomeActionStateModel {
    foo?: SomeResult;
    saving: boolean;
    saved: boolean;
    error: boolean;
    errorData?: ProblemDetailsError;
}

Waiting:

interface SomeActionStateModelWaiting {
    saving: false;
    saved: false;
    error: false;
}

Pending:

interface SomeActionStateModelPending {
    saving: true;
    saved: false;
    error: false;
}

Rejected:

interface SomeActionStateModelRejected {
    saving: false;
    saved: false;
    error: true;
    errorData: ProblemDetailsError;
}

Fulfilled:

interface SomeActionStateModelFulfilled {
    foo: SomeResult;
    saving: false;
    saved: true;
    error: false;
}
@acelaya acelaya added this to Shlink Nov 6, 2022
@acelaya acelaya added enhancement New feature or request tech-debt labels Nov 6, 2022
@acelaya acelaya added this to the 3.9.0 milestone Nov 13, 2022
@acelaya acelaya moved this to Todo 🗒️ in Shlink Dec 16, 2022
@acelaya acelaya removed the status in Shlink Dec 31, 2022
@acelaya acelaya removed this from the 3.9.0 milestone Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tech-debt
Projects
Status: No status
Development

No branches or pull requests

1 participant