Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
ca2f4836
Commit
ca2f4836
authored
Jan 24, 2015
by
Gerben
Committed by
Aron Carroll
Feb 04, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix scoping problems
parent
e0243919
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
15 deletions
+15
-15
annotation-sync.coffee
h/static/scripts/annotation-sync.coffee
+15
-15
No files found.
h/static/scripts/annotation-sync.coffee
View file @
ca2f4836
...
@@ -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
?
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment