HenrikJoreteg / redux-bundler

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

Feature/add destroy function to store #57

Closed rudionrails closed 5 years ago

rudionrails commented 5 years ago

TL;DR store.destroy() to remove event listeners, unsubscribe from store listeners or cleanup state.

Synopsis This feature has 2 interfaces: either return a function from bundle.init() or explicitly declare bundle.destroy(). Both 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.

HenrikJoreteg commented 5 years ago

This is really clean, I dig it!

I particularly like the pattern of returning the "unsubscribe" version of the function from adding event listeners and optionally returning a destroy method from init.

I think the only thing missing here is just some documentation for the /docs folder.

But overall, very nice.

rudionrails commented 5 years ago

Glad you like it so far. I would still need some help with this stuff here (may be affected by it)

Otherwise, I can add documentation on this for sure

rudionrails commented 5 years ago

Updated docs to cover store.destroy, bundle.destroy and bundle.init. Would be happy for a merge now :)

HenrikJoreteg commented 5 years ago

I'm still on vacation in Sweden. Thanks for your patience. Will try to review properly and merge sometime after I get back.

HenrikJoreteg commented 5 years ago

hey @rudionrails! I finally had a chance to do this.

I ended up actually removing the explicit bundle.destroy() support. Instead you have to return a cleanup method from init().

I did this because I didn't want to introduce multiple ways to do the same thing. And especially in the case of event listeners it seemed more likely that you've have the relevant listeners available in scope by doing it in init. Plus... it more closely matches patterns established elsewhere in the code.

Hope that's ok.

Anyway... released at 26.0.0 Thanks again!

rudionrails commented 5 years ago

Perfect. Thanks :)