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
6dc9ad86
Commit
6dc9ad86
authored
Apr 13, 2020
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `watch` utility in `frame-sync`
parent
c313ec3b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
59 deletions
+50
-59
frame-sync.js
src/sidebar/services/frame-sync.js
+49
-58
frame-sync-test.js
src/sidebar/services/test/frame-sync-test.js
+1
-1
No files found.
src/sidebar/services/frame-sync.js
View file @
6dc9ad86
...
@@ -5,6 +5,7 @@ import events from '../events';
...
@@ -5,6 +5,7 @@ import events from '../events';
import
Discovery
from
'../../shared/discovery'
;
import
Discovery
from
'../../shared/discovery'
;
import
uiConstants
from
'../ui-constants'
;
import
uiConstants
from
'../ui-constants'
;
import
*
as
metadata
from
'../util/annotation-metadata'
;
import
*
as
metadata
from
'../util/annotation-metadata'
;
import
{
watch
}
from
'../util/watch'
;
/**
/**
* @typedef FrameInfo
* @typedef FrameInfo
...
@@ -49,76 +50,66 @@ export default function FrameSync($rootScope, $window, store, bridge) {
...
@@ -49,76 +50,66 @@ export default function FrameSync($rootScope, $window, store, bridge) {
* notify connected frames about new/updated/deleted annotations.
* notify connected frames about new/updated/deleted annotations.
*/
*/
function
setupSyncToFrame
()
{
function
setupSyncToFrame
()
{
// List of loaded annotations in previous state
let
prevAnnotations
=
[];
let
prevFrames
=
[];
let
prevPublicAnns
=
0
;
let
prevPublicAnns
=
0
;
store
.
subscribe
(
function
()
{
watch
(
const
state
=
store
.
getState
();
store
.
subscribe
,
if
(
[()
=>
store
.
getState
().
annotations
.
annotations
,
()
=>
store
.
frames
()],
state
.
annotations
.
annotations
===
prevAnnotations
&&
([
annotations
,
frames
],
[
prevAnnotations
])
=>
{
state
.
frames
===
prevFrames
let
publicAnns
=
0
;
)
{
const
inSidebar
=
new
Set
();
return
;
const
added
=
[];
}
let
publicAnns
=
0
;
annotations
.
forEach
(
function
(
annot
)
{
const
inSidebar
=
new
Set
();
if
(
metadata
.
isReply
(
annot
))
{
const
added
=
[];
// The frame does not need to know about replies
return
;
}
state
.
annotations
.
annotations
.
forEach
(
function
(
annot
)
{
if
(
metadata
.
isPublic
(
annot
))
{
if
(
metadata
.
isReply
(
annot
))
{
++
publicAnns
;
// The frame does not need to know about replies
}
return
;
}
if
(
metadata
.
isPublic
(
annot
))
{
inSidebar
.
add
(
annot
.
$tag
);
++
publicAnns
;
if
(
!
inFrame
.
has
(
annot
.
$tag
))
{
}
added
.
push
(
annot
);
}
});
const
deleted
=
prevAnnotations
.
filter
(
function
(
annot
)
{
return
!
inSidebar
.
has
(
annot
.
$tag
);
});
inSidebar
.
add
(
annot
.
$tag
);
// We currently only handle adding and removing annotations from the frame
if
(
!
inFrame
.
has
(
annot
.
$tag
))
{
// when they are added or removed in the sidebar, but not re-anchoring
added
.
push
(
annot
);
// annotations if their selectors are updated.
if
(
added
.
length
>
0
)
{
bridge
.
call
(
'loadAnnotations'
,
added
.
map
(
formatAnnot
));
added
.
forEach
(
function
(
annot
)
{
inFrame
.
add
(
annot
.
$tag
);
});
}
}
});
deleted
.
forEach
(
function
(
annot
)
{
const
deleted
=
prevAnnotations
.
filter
(
function
(
annot
)
{
bridge
.
call
(
'deleteAnnotation'
,
formatAnnot
(
annot
));
return
!
inSidebar
.
has
(
annot
.
$tag
);
inFrame
.
delete
(
annot
.
$tag
);
});
prevAnnotations
=
state
.
annotations
.
annotations
;
prevFrames
=
state
.
frames
;
// We currently only handle adding and removing annotations from the frame
// when they are added or removed in the sidebar, but not re-anchoring
// annotations if their selectors are updated.
if
(
added
.
length
>
0
)
{
bridge
.
call
(
'loadAnnotations'
,
added
.
map
(
formatAnnot
));
added
.
forEach
(
function
(
annot
)
{
inFrame
.
add
(
annot
.
$tag
);
});
});
}
deleted
.
forEach
(
function
(
annot
)
{
bridge
.
call
(
'deleteAnnotation'
,
formatAnnot
(
annot
));
inFrame
.
delete
(
annot
.
$tag
);
});
const
frames
=
store
.
frames
();
if
(
frames
.
length
>
0
)
{
if
(
frames
.
length
>
0
)
{
if
(
if
(
frames
.
every
(
function
(
frame
)
{
frames
.
every
(
function
(
frame
)
{
return
frame
.
isAnnotationFetchComplete
;
return
frame
.
isAnnotationFetchComplete
;
})
})
)
{
)
{
if
(
publicAnns
===
0
||
publicAnns
!==
prevPublicAnns
)
{
if
(
publicAnns
===
0
||
publicAnns
!==
prevPublicAnns
)
{
bridge
.
call
(
bridge
.
call
(
bridgeEvents
.
PUBLIC_ANNOTATION_COUNT_CHANGED
,
bridgeEvents
.
PUBLIC_ANNOTATION_COUNT_CHANGED
,
publicAnns
publicAnns
);
)
;
prevPublicAnns
=
publicAnns
;
prevPublicAnns
=
publicAnns
;
}
}
}
}
}
}
}
}
);
);
}
}
/**
/**
...
...
src/sidebar/services/test/frame-sync-test.js
View file @
6dc9ad86
...
@@ -55,7 +55,7 @@ describe('sidebar/services/frame-sync', function () {
...
@@ -55,7 +55,7 @@ describe('sidebar/services/frame-sync', function () {
beforeEach
(
function
()
{
beforeEach
(
function
()
{
fakeStore
=
createFakeStore
(
fakeStore
=
createFakeStore
(
{
annotations
:
[]
},
{
annotations
:
{
annotations
:
[]
}
},
{
{
connectFrame
:
sinon
.
stub
(),
connectFrame
:
sinon
.
stub
(),
destroyFrame
:
sinon
.
stub
(),
destroyFrame
:
sinon
.
stub
(),
...
...
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