Commit ca2f4836 authored by Gerben's avatar Gerben Committed by Aron Carroll

Fix scoping problems

parent e0243919
...@@ -38,11 +38,11 @@ class AnnotationSync ...@@ -38,11 +38,11 @@ class AnnotationSync
# Listen locally for interesting events # Listen locally for interesting events
for event, handler of @_eventListeners for event, handler of @_eventListeners
this._on(event, handler) this._on(event, handler.bind(this))
# Register remotely invokable methods # Register remotely invokable methods
for method, func of @_channelListeners for method, func of @_channelListeners
@bridge.on(method, func) @bridge.on(method, func.bind(this))
# Upon new connections, send over the items in our cache # Upon new connections, send over the items in our cache
onConnect = (channel) => onConnect = (channel) =>
...@@ -56,21 +56,21 @@ class AnnotationSync ...@@ -56,21 +56,21 @@ class AnnotationSync
# Handlers for messages arriving through a channel # Handlers for messages arriving through a channel
_channelListeners: _channelListeners:
'beforeCreateAnnotation': (txn, annotation) => 'beforeCreateAnnotation': (txn, annotation) ->
annotation = this._parse annotation annotation = this._parse annotation
delete @cache[annotation.$$tag] delete @cache[annotation.$$tag]
@_emit 'beforeAnnotationCreated', annotation @_emit 'beforeAnnotationCreated', annotation
@cache[annotation.$$tag] = annotation @cache[annotation.$$tag] = annotation
this._format annotation this._format annotation
'createAnnotation': (txn, annotation) => 'createAnnotation': (txn, annotation) ->
annotation = this._parse annotation annotation = this._parse annotation
delete @cache[annotation.$$tag] delete @cache[annotation.$$tag]
@_emit 'annotationCreated', annotation @_emit 'annotationCreated', annotation
@cache[annotation.$$tag] = annotation @cache[annotation.$$tag] = annotation
this._format annotation this._format annotation
'updateAnnotation': (txn, annotation) => 'updateAnnotation': (txn, annotation) ->
annotation = this._parse annotation annotation = this._parse annotation
delete @cache[annotation.$$tag] delete @cache[annotation.$$tag]
@_emit('beforeAnnotationUpdated', [annotation]) @_emit('beforeAnnotationUpdated', [annotation])
...@@ -78,7 +78,7 @@ class AnnotationSync ...@@ -78,7 +78,7 @@ class AnnotationSync
@cache[annotation.$$tag] = annotation @cache[annotation.$$tag] = annotation
this._format annotation this._format annotation
'deleteAnnotation': (txn, annotation) => 'deleteAnnotation': (txn, annotation) ->
annotation = this._parse annotation annotation = this._parse annotation
delete @cache[annotation.$$tag] delete @cache[annotation.$$tag]
@_emit('annotationDeleted', [annotation]) @_emit('annotationDeleted', [annotation])
...@@ -86,38 +86,38 @@ class AnnotationSync ...@@ -86,38 +86,38 @@ class AnnotationSync
delete @cache[annotation.$$tag] delete @cache[annotation.$$tag]
res res
'sync': (ctx, annotations) => 'sync': (ctx, annotations) ->
(this._format (this._parse a) for a in annotations) (this._format (this._parse a) for a in annotations)
'loadAnnotations': (txn, annotations) => 'loadAnnotations': (txn, annotations) ->
annotations = (this._parse a for a in annotations) annotations = (this._parse a for a in annotations)
@_emit('loadAnnotations', annotations) @_emit('loadAnnotations', annotations)
# 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': (event, annotation) => 'beforeAnnotationCreated': (event, annotation) ->
return if annotation.$$tag? return if annotation.$$tag?
this._mkCallRemotelyAndParseResults('beforeCreateAnnotation')(annotation) this._mkCallRemotelyAndParseResults('beforeCreateAnnotation')(annotation)
this this
'annotationCreated': (event, annotation) => 'annotationCreated': (event, annotation) ->
return unless annotation.$$tag? and @cache[annotation.$$tag] return unless annotation.$$tag? and @cache[annotation.$$tag]
this._mkCallRemotelyAndParseResults('createAnnotation')(annotation) this._mkCallRemotelyAndParseResults('createAnnotation')(annotation)
this this
'annotationUpdated': (event, annotation) => 'annotationUpdated': (event, annotation) ->
return unless annotation.$$tag? and @cache[annotation.$$tag] return unless annotation.$$tag? and @cache[annotation.$$tag]
this._mkCallRemotelyAndParseResults('updateAnnotation')(annotation) this._mkCallRemotelyAndParseResults('updateAnnotation')(annotation)
this this
'annotationDeleted': (event, annotation) => 'annotationDeleted': (event, annotation) ->
return unless annotation.$$tag? and @cache[annotation.$$tag] return unless annotation.$$tag? and @cache[annotation.$$tag]
onFailure = (err) => onFailure = (err) =>
delete @cache[annotation.$$tag] unless err delete @cache[annotation.$$tag] unless err
this._mkCallRemotelyAndParseResults('deleteAnnotation', onFailure)(annotation) this._mkCallRemotelyAndParseResults('deleteAnnotation', onFailure)(annotation)
this this
'annotationsLoaded': (event, annotations) => 'annotationsLoaded': (event, annotations) ->
annotations = (this._format a for a in annotations when not a.$$tag) annotations = (this._format a for a in annotations when not a.$$tag)
return unless annotations.length return unless annotations.length
this._notify this._notify
...@@ -125,7 +125,7 @@ class AnnotationSync ...@@ -125,7 +125,7 @@ class AnnotationSync
params: annotations params: annotations
this this
_syncCache: (channel) => _syncCache: (channel) ->
# Synchronise (here to there) the items in our cache # Synchronise (here to there) the items in our cache
annotations = (this._format a for t, a of @cache) annotations = (this._format a for t, a of @cache)
if annotations.length if annotations.length
...@@ -134,7 +134,7 @@ class AnnotationSync ...@@ -134,7 +134,7 @@ class AnnotationSync
params: annotations params: annotations
_mkCallRemotelyAndParseResults: (method, callBack) -> _mkCallRemotelyAndParseResults: (method, callBack) ->
(annotation) -> (annotation) =>
# Wrap the callback function to first parse returned items # Wrap the callback function to first parse returned items
wrappedCallback = (failure, results) => wrappedCallback = (failure, results) =>
unless failure? unless failure?
......
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