Commit 74d0c30f authored by csillag's avatar csillag

Annotation loading cleanup #1

Manually cherry-pick some changes from

https://github.com/hypothesis/h/commit/c2286994a215283addd86170851e4cabf3e97ca9
https://github.com/hypothesis/h/commit/1ff5505f3b019e2abd21b6920a388d798c0acc58
https://github.com/hypothesis/h/commit/fa9351f02c996cebf8a10f1ef8bb8bbaa1035286

This partially takes care of
 * Problem 1 described in #578. (The two code path are not yet consolidated, but at least now they do the same)
 * Problem 3 (The reloading is now a separate method.)
parent 372c9362
......@@ -144,29 +144,7 @@ class App
plugins.Permissions.setUser(null)
delete plugins.Auth
if annotator.plugins.Store?
$scope.$root.annotations = []
annotator.threading.thread []
Store = annotator.plugins.Store
annotations = Store.annotations
annotator.plugins.Store.annotations = []
annotator.deleteAnnotation a for a in annotations
# XXX: Hacky hacky stuff to ensure that any search requests in-flight
# at this time have no effect when they resolve and that future events
# have no effect on this Store. Unfortunately, it's not possible to
# unregister all the events or properly unload the Store because the
# registration loses the closure. The approach here is perhaps
# cleaner than fishing them out of the jQuery private data.
# * Overwrite the Store's handle to the annotator, giving it one
# with a noop `loadAnnotations` method.
Store.annotator = loadAnnotations: angular.noop
# * Make all api requests into a noop.
Store._apiRequest = angular.noop
# * Remove the plugin and re-add it to the annotator.
delete annotator.plugins.Store
annotator.addStore Store.options
$scope.reloadAnnotations()
if newValue? and annotator.ongoing_edit
$timeout =>
......@@ -411,6 +389,36 @@ class App
@visualSearch.searchBox.searchEvent('')
, 1500
$scope.reloadAnnotations = =>
if annotator.plugins.Store?
$scope.$root.annotations = []
annotator.threading.thread []
Store = annotator.plugins.Store
annotations = Store.annotations
annotator.plugins.Store.annotations = []
annotator.deleteAnnotation a for a in annotations
# XXX: Hacky hacky stuff to ensure that any search requests in-flight
# at this time have no effect when they resolve and that future events
# have no effect on this Store. Unfortunately, it's not possible to
# unregister all the events or properly unload the Store because the
# registration loses the closure. The approach here is perhaps
# cleaner than fishing them out of the jQuery private data.
# * Overwrite the Store's handle to the annotator, giving it one
# with a noop `loadAnnotations` method.
Store.annotator = loadAnnotations: angular.noop
# * Make all api requests into a noop.
Store._apiRequest = angular.noop
# * Remove the plugin and re-add it to the annotator.
delete annotator.plugins.Store
annotator.addStore Store.options
href = annotator.plugins.Store.options.loadFromSearch.uri
for uri in annotator.plugins.Document.uris()
unless uri is href
annotator.plugins.Store.loadAnnotationsFromSearch uri: uri
class Annotation
this.$inject = ['$element', '$location', '$scope', 'annotator', 'drafts', '$timeout', '$window']
constructor: ($element, $location, $scope, annotator, drafts, $timeout, $window) ->
......
......@@ -368,9 +368,9 @@ class Hypothesis extends Annotator
console.log "Loaded annotions for '" + href + "'."
for uri in @plugins.Document.uris()
console.log "Also loading annotations for: " + uri
this.plugins.Store.loadAnnotationsFromSearch uri: uri
unless uri is href # Do not load the href again
console.log "Also loading annotations for: " + uri
this.plugins.Store.loadAnnotationsFromSearch uri: uri
class AuthenticationProvider
constructor: ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment