Commit 0e523df3 authored by Robert Knight's avatar Robert Knight

Use store selectors instead of `getState` in `FrameSyncService`

Remove the last remaining usage of `store.getState()` outside of the
store implementation in favor of the `store.allAnnotations()` selector
method.

This allows simplifying the state structure in the fake store that the
`FrameSyncService` tests create.
parent 4b7c566d
......@@ -66,7 +66,7 @@ export class FrameSyncService {
watch(
store.subscribe,
[() => store.getState().annotations.annotations, () => store.frames()],
[() => store.allAnnotations(), () => store.frames()],
([annotations, frames], [prevAnnotations]) => {
let publicAnns = 0;
const inSidebar = new Set();
......
......@@ -54,8 +54,11 @@ describe('FrameSyncService', () => {
beforeEach(function () {
fakeStore = createFakeStore(
{ annotations: { annotations: [] } },
{ annotations: [] },
{
allAnnotations() {
return this.getState().annotations;
},
connectFrame: sinon.stub(),
destroyFrame: sinon.stub(),
findIDsForTags: sinon.stub(),
......@@ -110,7 +113,7 @@ describe('FrameSyncService', () => {
context('when annotations are loaded into the sidebar', function () {
it('sends a "loadAnnotations" message to the frame', function () {
fakeStore.setState({
annotations: { annotations: [fixtures.ann] },
annotations: [fixtures.ann],
});
assert.calledWithMatch(
fakeBridge.call,
......@@ -122,12 +125,12 @@ describe('FrameSyncService', () => {
it('sends a "loadAnnotations" message only for new annotations', function () {
const ann2 = Object.assign({}, fixtures.ann, { $tag: 't2', id: 'a2' });
fakeStore.setState({
annotations: { annotations: [fixtures.ann] },
annotations: [fixtures.ann],
});
fakeBridge.call.reset();
fakeStore.setState({
annotations: { annotations: [fixtures.ann, ann2] },
annotations: [fixtures.ann, ann2],
});
assert.calledWithMatch(
......@@ -139,7 +142,7 @@ describe('FrameSyncService', () => {
it('does not send a "loadAnnotations" message for replies', function () {
fakeStore.setState({
annotations: { annotations: [annotationFixtures.newReply()] },
annotations: [annotationFixtures.newReply()],
});
assert.isFalse(fakeBridge.call.calledWith('loadAnnotations'));
});
......@@ -148,7 +151,7 @@ describe('FrameSyncService', () => {
context('when annotation count has changed', function () {
it('sends a "publicAnnotationCountChanged" message to the frame when there are public annotations', function () {
fakeStore.setState({
annotations: { annotations: [annotationFixtures.publicAnnotation()] },
annotations: [annotationFixtures.publicAnnotation()],
});
assert.calledWithMatch(
fakeBridge.call,
......@@ -162,7 +165,7 @@ describe('FrameSyncService', () => {
delete annot.permissions;
fakeStore.setState({
annotations: { annotations: [annot] },
annotations: [annot],
});
assert.calledWithMatch(
fakeBridge.call,
......@@ -174,7 +177,7 @@ describe('FrameSyncService', () => {
it('does not send a "publicAnnotationCountChanged" message to the frame if annotation fetch is not complete', function () {
fakeStore.frames.returns([{ uri: 'http://example.com' }]);
fakeStore.setState({
annotations: { annotations: [annotationFixtures.publicAnnotation()] },
annotations: [annotationFixtures.publicAnnotation()],
});
assert.isFalse(
fakeBridge.call.calledWith('publicAnnotationCountChanged')
......@@ -184,7 +187,7 @@ describe('FrameSyncService', () => {
it('does not send a "publicAnnotationCountChanged" message if there are no connected frames', function () {
fakeStore.frames.returns([]);
fakeStore.setState({
annotations: { annotations: [annotationFixtures.publicAnnotation()] },
annotations: [annotationFixtures.publicAnnotation()],
});
assert.isFalse(
fakeBridge.call.calledWith('publicAnnotationCountChanged')
......@@ -195,10 +198,10 @@ describe('FrameSyncService', () => {
context('when annotations are removed from the sidebar', function () {
it('sends a "deleteAnnotation" message to the frame', function () {
fakeStore.setState({
annotations: { annotations: [fixtures.ann] },
annotations: [fixtures.ann],
});
fakeStore.setState({
annotations: { annotations: [] },
annotations: [],
});
assert.calledWithMatch(
fakeBridge.call,
......
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