Coder Social home page Coder Social logo

Broken bind/unbind logic about pusher-angular HOT 5 CLOSED

pusher avatar pusher commented on June 15, 2024
Broken bind/unbind logic

from pusher-angular.

Comments (5)

hamchapman avatar hamchapman commented on June 15, 2024

I'll take a look into this today - do you have some example code that shows it because as far as I can tell, the tests suggest that it is working

from pusher-angular.

Disparity avatar Disparity commented on June 15, 2024

Example here: http://disparity.github.io/pusher-issue/

The tests do not cover this case, because only check for calling, but not that it is passed.

The user does not know anything about the interior decorators who wraps his listeners.
And when you try to unbind - passed the original listener, not a decorator and unbind not occur.

bind decorator: https://github.com/pusher/pusher-angular/blob/master/lib/pusher-angular.js#L168-L171
unbind listener: https://github.com/pusher/pusher-angular/blob/master/lib/pusher-angular.js#L181

from pusher-angular.

hamchapman avatar hamchapman commented on June 15, 2024

This should be fixed now 👍

You now get back a decorated version of the callback / handler that you pass to bind when you call bind and so you can then use that to unbind.

I've pushed out 0.1.8 as a new version.

Thanks for raising the issue

from pusher-angular.

Disparity avatar Disparity commented on June 15, 2024

IMHO not a good idea to return a decorated handler. The user does not need to know the internal implementation, with the decorator.
Then it is better to return a deregistration function for this listener, like a $scope.$on, which is useful for:

var unbindFunction = pusher.bind(event, listener);
$scope.$on('$destroy', unbindFunction));

or

var unbindFunction = pusher.bind(event, listener);
unbindFunction();

or

$scope.$on('$destroy', pusher.bind(event, listener)));

instead of current implementation:

var decoratedHandler = pusher.bind(event, listener);
$scope.$on('$destroy', function () {
    pusher.unbind(event, decoratedHandler);
}));

from pusher-angular.

hamchapman avatar hamchapman commented on June 15, 2024

I can see the value of the different solutions you've described and they may well be more aligned with Angular conventions. I'm more than happy for you to make a pull request and I'll review it and likely merge it 👍

I only went with the solution I went with so that it was differing as little as possible from the pusher-js version.

from pusher-angular.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.