• 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
..
annotator Loading commit data...
directive Loading commit data...
filter Loading commit data...
test Loading commit data...
util Loading commit data...
vendor Loading commit data...
annotation-mapper.js Loading commit data...
annotation-metadata.js Loading commit data...
annotation-sync.coffee Loading commit data...
annotation-ui-controller.js Loading commit data...
annotation-ui-sync.js Loading commit data...
annotation-ui.js Loading commit data...
annotation-viewer-controller.js Loading commit data...
app-controller.js Loading commit data...
app.js Loading commit data...
auth.js Loading commit data...
bridge.coffee Loading commit data...
build-thread.js Loading commit data...
cross-frame.coffee Loading commit data...
date-util.js Loading commit data...
discovery.coffee Loading commit data...
drafts.js Loading commit data...
events.js Loading commit data...
features.js Loading commit data...
flash.coffee Loading commit data...
form-respond.coffee Loading commit data...
frame-rpc.js Loading commit data...
groups.js Loading commit data...
host.coffee Loading commit data...
karma-phantomjs-polyfill.js Loading commit data...
karma.config.js Loading commit data...
live-reload-client.js Loading commit data...
local-storage.coffee Loading commit data...
markdown-commands.js Loading commit data...
media-embedder.js Loading commit data...
permissions.coffee Loading commit data...
polyfills.js Loading commit data...
query-parser.coffee Loading commit data...
raven.js Loading commit data...
render-markdown.js Loading commit data...
retry-util.js Loading commit data...
root-thread.js Loading commit data...
search-client.js Loading commit data...
search-filter.coffee Loading commit data...
session.js Loading commit data...
settings.js Loading commit data...
store.js Loading commit data...
stream-controller.coffee Loading commit data...
stream-filter.coffee Loading commit data...
streamer.js Loading commit data...
tags.coffee Loading commit data...
time.js Loading commit data...
tsconfig.json Loading commit data...
ui-constants.js Loading commit data...
unicode.coffee Loading commit data...
view-filter.coffee Loading commit data...
virtual-thread-list.js Loading commit data...
websocket.js Loading commit data...
widget-controller.js Loading commit data...