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

No way to destroy an action #120

ds0nt opened this issue Nov 12, 2014 · 1 comment

No way to destroy an action #120

ds0nt opened this issue Nov 12, 2014 · 1 comment


Copy link

ds0nt commented Nov 12, 2014

Is there a way to destroy an action? I peeked at the code and didn't see anything and skimmed the npm and github pages.

Did I miss it?

Use Case:

<PrettyButton> //Generates an action fired onClick
  <PrettyButtonDialog action={prettybutton's action}> //Subscribes to prettybutton's action and toggles it's visibility

It has advantage over function, because I don't need to define an onclick from the container of these elements to proxy elements from PrettyButton into PrettyButton.props.children. They can all just listen to the action. And I can still use the same PrettyButton for many different Children

Problem is I don't want to leak actions everywhere... (when prettybutton dismounts and remounts)

Copy link

spoike commented Nov 12, 2014

That's not really how actions are designed to be used. You only create one action per data-flow that you want to initiate, which is done when the application is bootstrapping, and you're not supposed to "destroy" the actions (at least they weren't designed to be). You may however unsubscribe to them as subscriptions return an unsubscription function.

You can write a mixin that hooks up the action and unsubscribes like this:

var PrettyButtonDialogMixin = {
    componentDidMount: function() {
        this._unsubFunc = this.props.action.listen(this.onAction, this);
    componentDidUnmount: function() {
        if (this._unsubFunc) {

... and use it in your PrettyButtonDialog:

var PrettyButtonDialog = {
    mixins: [PrettyButtonDialogMixin],
    render: function() { /* snip snip */ }

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants