Commit ad56f9d7 authored by Sheetal Umesh Kumar's avatar Sheetal Umesh Kumar

Rename the `$$tag` annotation property to `$tag`.

This property previously had a "$$" prefix instead of the conventional
single "$" prefix for local-only properties of annotations for
historical reasons.

This is a followup PR to:
https://github.com/hypothesis/client/pull/126
parent cdaf5e8f
...@@ -40,7 +40,7 @@ module.exports = class AnnotationSync ...@@ -40,7 +40,7 @@ module.exports = class AnnotationSync
_channelListeners: _channelListeners:
'deleteAnnotation': (body, cb) -> 'deleteAnnotation': (body, cb) ->
annotation = this._parse(body) annotation = this._parse(body)
delete @cache[annotation.$$tag] delete @cache[annotation.$tag]
@_emit('annotationDeleted', annotation) @_emit('annotationDeleted', annotation)
cb(null, this._format(annotation)) cb(null, this._format(annotation))
...@@ -52,7 +52,7 @@ module.exports = class AnnotationSync ...@@ -52,7 +52,7 @@ module.exports = class AnnotationSync
# Handlers for events coming from this frame, to send them across the channel # Handlers for events coming from this frame, to send them across the channel
_eventListeners: _eventListeners:
'beforeAnnotationCreated': (annotation) -> 'beforeAnnotationCreated': (annotation) ->
return if annotation.$$tag? return if annotation.$tag?
this._mkCallRemotelyAndParseResults('beforeCreateAnnotation')(annotation) this._mkCallRemotelyAndParseResults('beforeCreateAnnotation')(annotation)
_mkCallRemotelyAndParseResults: (method, callBack) -> _mkCallRemotelyAndParseResults: (method, callBack) ->
...@@ -76,9 +76,9 @@ module.exports = class AnnotationSync ...@@ -76,9 +76,9 @@ module.exports = class AnnotationSync
# Assign a non-enumerable tag to objects which cross the bridge. # Assign a non-enumerable tag to objects which cross the bridge.
# This tag is used to identify the objects between message. # This tag is used to identify the objects between message.
_tag: (ann, tag) -> _tag: (ann, tag) ->
return ann if ann.$$tag return ann if ann.$tag
tag = tag or window.btoa(Math.random()) tag = tag or window.btoa(Math.random())
Object.defineProperty(ann, '$$tag', value: tag) Object.defineProperty(ann, '$tag', value: tag)
@cache[tag] = ann @cache[tag] = ann
ann ann
...@@ -93,6 +93,6 @@ module.exports = class AnnotationSync ...@@ -93,6 +93,6 @@ module.exports = class AnnotationSync
_format: (ann) -> _format: (ann) ->
this._tag(ann) this._tag(ann)
{ {
tag: ann.$$tag tag: ann.$tag
msg: ann msg: ann
} }
...@@ -125,12 +125,12 @@ module.exports = class Guest extends Annotator ...@@ -125,12 +125,12 @@ module.exports = class Guest extends Annotator
_connectAnnotationUISync: (crossframe) -> _connectAnnotationUISync: (crossframe) ->
crossframe.on 'focusAnnotations', (tags=[]) => crossframe.on 'focusAnnotations', (tags=[]) =>
for anchor in @anchors when anchor.highlights? for anchor in @anchors when anchor.highlights?
toggle = anchor.annotation.$$tag in tags toggle = anchor.annotation.$tag in tags
$(anchor.highlights).toggleClass('annotator-hl-focused', toggle) $(anchor.highlights).toggleClass('annotator-hl-focused', toggle)
crossframe.on 'scrollToAnnotation', (tag) => crossframe.on 'scrollToAnnotation', (tag) =>
for anchor in @anchors when anchor.highlights? for anchor in @anchors when anchor.highlights?
if anchor.annotation.$$tag is tag if anchor.annotation.$tag is tag
scrollIntoView(anchor.highlights[0]) scrollIntoView(anchor.highlights[0])
crossframe.on 'getDocumentInfo', (cb) => crossframe.on 'getDocumentInfo', (cb) =>
...@@ -348,19 +348,19 @@ module.exports = class Guest extends Annotator ...@@ -348,19 +348,19 @@ module.exports = class Guest extends Annotator
annotation annotation
showAnnotations: (annotations) -> showAnnotations: (annotations) ->
tags = (a.$$tag for a in annotations) tags = (a.$tag for a in annotations)
@crossframe?.call('showAnnotations', tags) @crossframe?.call('showAnnotations', tags)
toggleAnnotationSelection: (annotations) -> toggleAnnotationSelection: (annotations) ->
tags = (a.$$tag for a in annotations) tags = (a.$tag for a in annotations)
@crossframe?.call('toggleAnnotationSelection', tags) @crossframe?.call('toggleAnnotationSelection', tags)
updateAnnotations: (annotations) -> updateAnnotations: (annotations) ->
tags = (a.$$tag for a in annotations) tags = (a.$tag for a in annotations)
@crossframe?.call('updateAnnotations', tags) @crossframe?.call('updateAnnotations', tags)
focusAnnotations: (annotations) -> focusAnnotations: (annotations) ->
tags = (a.$$tag for a in annotations) tags = (a.$tag for a in annotations)
@crossframe?.call('focusAnnotations', tags) @crossframe?.call('focusAnnotations', tags)
_onSelection: (range) -> _onSelection: (range) ->
......
...@@ -36,7 +36,7 @@ describe 'AnnotationSync', -> ...@@ -36,7 +36,7 @@ describe 'AnnotationSync', ->
describe 'channel event handlers', -> describe 'channel event handlers', ->
assertBroadcast = (channelEvent, publishEvent) -> assertBroadcast = (channelEvent, publishEvent) ->
it 'broadcasts the "' + publishEvent + '" event over the local event bus', -> it 'broadcasts the "' + publishEvent + '" event over the local event bus', ->
ann = {id: 1, $$tag: 'tag1'} ann = {id: 1, $tag: 'tag1'}
annSync = createAnnotationSync() annSync = createAnnotationSync()
eventStub = sinon.stub() eventStub = sinon.stub()
options.on(publishEvent, eventStub) options.on(publishEvent, eventStub)
...@@ -47,7 +47,7 @@ describe 'AnnotationSync', -> ...@@ -47,7 +47,7 @@ describe 'AnnotationSync', ->
assertReturnValue = (channelEvent) -> assertReturnValue = (channelEvent) ->
it 'calls back with a formatted annotation', (done) -> it 'calls back with a formatted annotation', (done) ->
ann = {id: 1, $$tag: 'tag1'} ann = {id: 1, $tag: 'tag1'}
annSync = createAnnotationSync() annSync = createAnnotationSync()
callback = (err, ret) -> callback = (err, ret) ->
...@@ -60,14 +60,14 @@ describe 'AnnotationSync', -> ...@@ -60,14 +60,14 @@ describe 'AnnotationSync', ->
it 'removes an existing entry from the cache before the event is triggered', -> it 'removes an existing entry from the cache before the event is triggered', ->
options.emit = -> assert(!annSync.cache['tag1']) options.emit = -> assert(!annSync.cache['tag1'])
ann = {id: 1, $$tag: 'tag1'} ann = {id: 1, $tag: 'tag1'}
annSync = createAnnotationSync() annSync = createAnnotationSync()
annSync.cache['tag1'] = ann annSync.cache['tag1'] = ann
publish(channelEvent, {msg: ann}, ->) publish(channelEvent, {msg: ann}, ->)
it 'ensures the annotation is inserted in the cache', -> it 'ensures the annotation is inserted in the cache', ->
ann = {id: 1, $$tag: 'tag1'} ann = {id: 1, $tag: 'tag1'}
annSync = createAnnotationSync() annSync = createAnnotationSync()
publish(channelEvent, {msg: ann}, ->) publish(channelEvent, {msg: ann}, ->)
...@@ -81,14 +81,14 @@ describe 'AnnotationSync', -> ...@@ -81,14 +81,14 @@ describe 'AnnotationSync', ->
it 'removes an existing entry from the cache before the event is triggered', -> it 'removes an existing entry from the cache before the event is triggered', ->
options.emit = -> assert(!annSync.cache['tag1']) options.emit = -> assert(!annSync.cache['tag1'])
ann = {id: 1, $$tag: 'tag1'} ann = {id: 1, $tag: 'tag1'}
annSync = createAnnotationSync() annSync = createAnnotationSync()
annSync.cache['tag1'] = ann annSync.cache['tag1'] = ann
publish('deleteAnnotation', {msg: ann}, ->) publish('deleteAnnotation', {msg: ann}, ->)
it 'removes the annotation from the cache', -> it 'removes the annotation from the cache', ->
ann = {id: 1, $$tag: 'tag1'} ann = {id: 1, $tag: 'tag1'}
annSync = createAnnotationSync() annSync = createAnnotationSync()
publish('deleteAnnotation', {msg: ann}, ->) publish('deleteAnnotation', {msg: ann}, ->)
...@@ -101,8 +101,8 @@ describe 'AnnotationSync', -> ...@@ -101,8 +101,8 @@ describe 'AnnotationSync', ->
options.on('annotationsLoaded', loadedStub) options.on('annotationsLoaded', loadedStub)
annSync = createAnnotationSync() annSync = createAnnotationSync()
annotations = [{id: 1, $$tag: 'tag1'}, {id: 2, $$tag: 'tag2'}, {id: 3, $$tag: 'tag3'}] annotations = [{id: 1, $tag: 'tag1'}, {id: 2, $tag: 'tag2'}, {id: 3, $tag: 'tag3'}]
bodies = ({msg: ann, tag: ann.$$tag} for ann in annotations) bodies = ({msg: ann, tag: ann.$tag} for ann in annotations)
publish('loadAnnotations', bodies, ->) publish('loadAnnotations', bodies, ->)
assert.calledWith(loadedStub, annotations) assert.calledWith(loadedStub, annotations)
...@@ -116,10 +116,10 @@ describe 'AnnotationSync', -> ...@@ -116,10 +116,10 @@ describe 'AnnotationSync', ->
assert.called(fakeBridge.call) assert.called(fakeBridge.call)
assert.calledWith(fakeBridge.call, 'beforeCreateAnnotation', assert.calledWith(fakeBridge.call, 'beforeCreateAnnotation',
{msg: ann, tag: ann.$$tag}, sinon.match.func) {msg: ann, tag: ann.$tag}, sinon.match.func)
it 'returns early if the annotation has a tag', -> it 'returns early if the annotation has a tag', ->
ann = {id: 1, $$tag: 'tag1'} ann = {id: 1, $tag: 'tag1'}
annSync = createAnnotationSync() annSync = createAnnotationSync()
options.emit('beforeAnnotationCreated', ann) options.emit('beforeAnnotationCreated', ann)
......
...@@ -124,15 +124,15 @@ describe 'Guest', -> ...@@ -124,15 +124,15 @@ describe 'Guest', ->
options = CrossFrame.lastCall.args[1] options = CrossFrame.lastCall.args[1]
it 'detaches annotations on "annotationDeleted"', -> it 'detaches annotations on "annotationDeleted"', ->
ann = {id: 1, $$tag: 'tag1'} ann = {id: 1, $tag: 'tag1'}
sandbox.stub(guest, 'detach') sandbox.stub(guest, 'detach')
options.emit('annotationDeleted', ann) options.emit('annotationDeleted', ann)
assert.calledOnce(guest.detach) assert.calledOnce(guest.detach)
assert.calledWith(guest.detach, ann) assert.calledWith(guest.detach, ann)
it 'anchors annotations on "annotationsLoaded"', -> it 'anchors annotations on "annotationsLoaded"', ->
ann1 = {id: 1, $$tag: 'tag1'} ann1 = {id: 1, $tag: 'tag1'}
ann2 = {id: 2, $$tag: 'tag2'} ann2 = {id: 2, $tag: 'tag2'}
sandbox.stub(guest, 'anchor') sandbox.stub(guest, 'anchor')
options.emit('annotationsLoaded', [ann1, ann2]) options.emit('annotationsLoaded', [ann1, ann2])
assert.calledTwice(guest.anchor) assert.calledTwice(guest.anchor)
...@@ -162,8 +162,8 @@ describe 'Guest', -> ...@@ -162,8 +162,8 @@ describe 'Guest', ->
highlight1 = $('<span></span>') highlight1 = $('<span></span>')
guest = createGuest() guest = createGuest()
guest.anchors = [ guest.anchors = [
{annotation: {$$tag: 'tag1'}, highlights: highlight0.toArray()} {annotation: {$tag: 'tag1'}, highlights: highlight0.toArray()}
{annotation: {$$tag: 'tag2'}, highlights: highlight1.toArray()} {annotation: {$tag: 'tag2'}, highlights: highlight1.toArray()}
] ]
emitGuestEvent('focusAnnotations', ['tag1']) emitGuestEvent('focusAnnotations', ['tag1'])
assert.isTrue(highlight0.hasClass('annotator-hl-focused')) assert.isTrue(highlight0.hasClass('annotator-hl-focused'))
...@@ -173,8 +173,8 @@ describe 'Guest', -> ...@@ -173,8 +173,8 @@ describe 'Guest', ->
highlight1 = $('<span class="annotator-hl-focused"></span>') highlight1 = $('<span class="annotator-hl-focused"></span>')
guest = createGuest() guest = createGuest()
guest.anchors = [ guest.anchors = [
{annotation: {$$tag: 'tag1'}, highlights: highlight0.toArray()} {annotation: {$tag: 'tag1'}, highlights: highlight0.toArray()}
{annotation: {$$tag: 'tag2'}, highlights: highlight1.toArray()} {annotation: {$tag: 'tag2'}, highlights: highlight1.toArray()}
] ]
emitGuestEvent('focusAnnotations', 'ctx', ['tag1']) emitGuestEvent('focusAnnotations', 'ctx', ['tag1'])
assert.isFalse(highlight1.hasClass('annotator-hl-focused')) assert.isFalse(highlight1.hasClass('annotator-hl-focused'))
...@@ -188,7 +188,7 @@ describe 'Guest', -> ...@@ -188,7 +188,7 @@ describe 'Guest', ->
highlight = $('<span></span>') highlight = $('<span></span>')
guest = createGuest() guest = createGuest()
guest.anchors = [ guest.anchors = [
{annotation: {$$tag: 'tag1'}, highlights: highlight.toArray()} {annotation: {$tag: 'tag1'}, highlights: highlight.toArray()}
] ]
emitGuestEvent('scrollToAnnotation', 'tag1') emitGuestEvent('scrollToAnnotation', 'tag1')
assert.called(scrollIntoView) assert.called(scrollIntoView)
......
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