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

Ability to do cleanup on store destroy #97

Closed
anacierdem opened this issue Sep 14, 2020 · 1 comment
Closed

Ability to do cleanup on store destroy #97

anacierdem opened this issue Sep 14, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@anacierdem
Copy link

anacierdem commented Sep 14, 2020

Currently, thecreateContainer provides an ability to do some cleanup on a per-container basis. It is also possible to create a single store instance shared among a number of containers and know when each of them is destroyed.

const Container = createContainer(Store, {
  onCleanup: () => {
    // This is run for every container that gets destroyed.
  }
});

Then when rendering we can do;

<Container scope="my-scope"> ... </..

We also know that by design RSS destroys the store when there are no more containers left in a given scope (for this case my-scope). Currently there is not an integrated way of knowing when the store is destroyed. This can become necessary for example to abort all ongoing requests.

As a solution consider;

const Container = createContainer(Store, {
  onDestroy: () => {
    // This is run when the store is destroyed.
  }
});

Or there may be alternatives where we can 'deduce' when to do the final cleanup, for example providing number of containers left as a prop to onCleanup etc.

@albertogasparin
Copy link
Collaborator

This is now supported as part of the improved Store/Container API #198 .
Basically by using the new containedBy attribute on store creation we also support handlers.onDestroy.

See docs. It will be available on v2.7.0+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants