Commit fcf26aea authored by csillag's avatar csillag

Bridge plugin: announce changes received for existing annotations

When we receive updated versions of existing annotations from the
other side of the bridge, not only merge those changes,
but announce them with the appropriate event, too.

Based on changes originally introduced here:
https://github.com/hypothesis/h/commit/1d4e9f32cc4f8c7db5ffdac7adad90e9cbf88db6#diff-5
parent 9e33a67c
...@@ -156,11 +156,18 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin ...@@ -156,11 +156,18 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin
## Notifications ## Notifications
.bind('loadAnnotations', (txn, annotations) => .bind('loadAnnotations', (txn, annotations) =>
# First, parse the existing ones, for any updates # First, parse the existing ones, for any updates
this._parse a for a in annotations when @cache[a.tag] oldOnes = (this._parse a for a in annotations when @cache[a.tag])
# Announce the changes in old annotations
if oldOnes.length
@selfPublish = true
@annotator.publish 'annotationsLoaded', [oldOnes]
delete @selfPublish
# Then collect the new ones # Then collect the new ones
annotations = (this._parse a for a in annotations when not @cache[a.tag]) newOnes = (this._parse a for a in annotations when not @cache[a.tag])
if annotations.length if newOnes.length
@annotator.loadAnnotations annotations @annotator.loadAnnotations newOnes
) )
.bind('showEditor', (ctx, annotation) => .bind('showEditor', (ctx, annotation) =>
...@@ -285,6 +292,11 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin ...@@ -285,6 +292,11 @@ class Annotator.Plugin.Bridge extends Annotator.Plugin
this this
annotationsLoaded: (annotations) => annotationsLoaded: (annotations) =>
return if @selfPublish
unless annotations.length
console.log "Useless call to 'annotationsLoaded()' with an empty list"
console.trace()
return
this._notify this._notify
method: 'loadAnnotations' method: 'loadAnnotations'
params: (this._format a for a in annotations) params: (this._format a for a in annotations)
......
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