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

Fix stopReplying for non-function callback values #230

Closed
wants to merge 2 commits into from

Conversation

murphym18
Copy link

@paulfalgout made a good point on May 29, 2015 (see #162)

callbacks may be wrapped via the makeCallback function, so if your callback needs to be wrapped, you will not be able to call stopReplying as it won't have the wrapped callback for comparison.

This behavior seems less than ideal and my pull request would change it so that invoking stopReplying with a non-function callback value removes callback functions that makeCallback created for the said callback value.

I also added a test for calling stopReplying with a non-function callback value.

Note that removeHandler (line 89) checks the _callback property and my changes to makeCallback depend on that.

@paulfalgout
Copy link
Member

Thanks for this! A surprisingly elegant fix. @marionettejs/marionette-core ?

}
var result = function () { return callback; };
result._callback = callback;
return result;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to condense this logic into:

function makeCallback(val) {
  var callback = _.isFunction(val) ? val : function() { return val; };
  callback._original = val;
  return callback;
}

Then https://github.com/marionettejs/backbone.radio/blob/master/src/backbone.radio.js#L89 can be simplified to:

    if (
-      (!callback || (callback === event.callback || callback === event.callback._callback)) &&
+      (!callback || (callback === event.callback._original)) &&
       (!context || (context === event.context))
    ) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually looking at this quickly it looks like our replyOnce implementation is incorrect

See backbone

cc @jmeas @jridgewell.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhm, Radio's event implementation is outdated, in general.

@blikblum
Copy link
Contributor

Closing in favor of #278

@blikblum blikblum closed this Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants