HenrikJoreteg / redux-bundler

Compose a Redux store out of smaller bundles of functionality.
https://reduxbundler.com
583 stars 46 forks source link

Add `destroy` function to bundle #58

Closed rudionrails closed 4 years ago

rudionrails commented 4 years ago

Hi @HenrikJoreteg

TL;DR

Add store.destroy() to remove event listeners, unsubscribe from store listeners or cleanup state.

I have already opened a PR (#57) for this, but some integration is still missing and I would like a review + feedback on the implementation (in case you are interested in merging it).

Synopsis

This feature has 2 interfaces:

Both interfaces also work together. It is a 1-way final method - no option to revert or re-initialize the store again. See test/destroy.js for reference.

Background

I am currently working on a distributed micro-frontend application. Every App is mounted or unmounted from a Shell application. On mount, the (micro) app is instantiated and for unmount, it is destroyed. With the reactor bundle (and others) the store.subscribe call leaves artifacts, like APP_IDLE, that are executed even when the App is removed already. Without this change, the store would never get garbage collected. Additionally, want to use it to cleanup other DOM event listeners.

HenrikJoreteg commented 4 years ago

This has been implemented in the last release