store icon indicating copy to clipboard operation
store copied to clipboard

Remove a fractal store

Open vvasabi opened this issue 7 years ago • 1 comments

This is a...

  • [x] feature request
  • [ ] bug report
  • [x] usage question

I have an Angular app that potentially allows an infinite number of widgets to be opened. Because each widget contains a form with rather complex logic, I am trying to use the fractal store pattern, giving a widget its own redux store.

By looking at the source code here: https://github.com/angular-redux/store/blob/master/src/components/fractal-reducer-map.ts, it seems that there is currently no way to remove local reducers from reducerMap. If I’m reading the source code correctly, reducerMap will keep growing, resulting in a memory leak.

My questions are therefore:

  • Is fractal store the correct pattern to use for my use case?
  • Is there a way to properly remove a sub store after it is configured, so there is no memory leak? If not, this would be a feature request.

Thank you!

vvasabi avatar Jan 10 '18 21:01 vvasabi

You are correct - I did not think of the case where components come and go. Or rather, I made the assumption that the substores would be keyed by some kind of persistent Id that could be re-used.

This is a good feature request. Unfortunately I'm not heavily involved in this project right now having changed jobs. However if you wanted to take a stab at it, one possible implementation would involve creating and exposing a destroySubStore method that would

  1. fire an internal action (e.g. @angular-redux::cleanup_fractal_store)
  2. remove all registered reducers rooted at or under that state path
  3. have rootFractalReducer listen for that action and delete the corresponding state from the store.

@e-schultz does any of that make sense?

SethDavenport avatar Mar 04 '18 23:03 SethDavenport