Skip to content

Operator's declaration sequence affects behavior when using synchronous adapters (e.g. LocalStorage) #38

@qunaxis

Description

@qunaxis

Operator's declaration sequence affects behavior when using synchronous adapters (e.g. LocalStorage)

Description

persist() runs synchronously (because localStorage is synchronous) and immediately pushes a done event that doesn't have any watches yet. I think this is also true for other events, such as finally.

Reproduce

Link: https://stackblitz.com/edit/react-ts-wdmuyv?devToolsHeight=33&file=App.tsx
How to use: write any value into input, reload the page and watch the console – there are missing dataLoaded event. Comment out the second debug, uncomment the first debug and see how it works.

Current solution

Move persist() operator after all related sample and other effector operators.

Suggestions

  1. Add a Warning/Caution in the documentation to pay the attention of library users to this fact – it's confusing and not easy to detect;
  2. Review related code to make it works according to Effector ecosystem ideology.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions