• Nick Stenning's avatar
    Avoid double-binding event handlers for streamer reconnection · 12ff84a3
    Nick Stenning authored
    Using `$rootScope.$on` to bind event handlers in a controller is usually
    going to result in bugs, because:
    
    - The lifecycle of `$rootScope` is that of the entire application --
      that is, it never gets torn down.
    - The lifecycle of the controller depends on when and where that
      controller is instantiated. In our case, logging in and logging out of
      the application triggers a route reload[1], which tears down the
      WidgetController.
    - WidgetController has no ability to unbind event handlers when it is
      torn down.
    
    Luckily the fix is relatively straightforward. Because this event is
    `$broadcast` on the root scope, it propagates to all child scopes. Thus,
    we can listen to the event on the controller's local `$scope` and ensure
    that the handlers are garbage collected along with the scope when the
    controller is torn down.
    
    [1]: https://github.com/hypothesis/client/blob/d6a1392/h/static/scripts/app-controller.js#L71
    12ff84a3
Name
Last commit
Last update
.github Loading commit data...
h Loading commit data...
images Loading commit data...
scripts Loading commit data...
.eslintignore Loading commit data...
.eslintrc Loading commit data...
.gitignore Loading commit data...
.npmignore Loading commit data...
.npmrc Loading commit data...
.travis.yml Loading commit data...
CHANGELOG.md Loading commit data...
CODE_OF_CONDUCT Loading commit data...
Jenkinsfile Loading commit data...
LICENSE Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
gulpfile.js Loading commit data...
npm-shrinkwrap.json Loading commit data...
package.json Loading commit data...