Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AnnotationUISync service #127

Merged
merged 3 commits into from
Nov 8, 2016
Merged

Conversation

robertknight
Copy link
Member

This consolidates all of the event handlers for messages coming from connected frames into the sidebar app into the FrameSync service and removes the AnnotationUISync service.

  • The listeners for showAnnotations, toggleAnnotationSelection, sidebarOpened and focusAnnotations messages have been moved into the FrameSync service
  • The logic for synchronizing the state of the Show Highlights toolbar button across multiple frames appears to be completely broken as far as I can see, so I just removed it. @nickstenning - Do you know if there are current uses of Hypothesis where there are guests (as in Annotator.Guest) that are not in the same frame as the host? If so I'll need to re-instate this.

The functionality related to highlight visibility that does work which we will still need to support is:

  1. Toggling highlight visibility when clicking the Show Highlights button when there is a single connected frame
  2. Respecting the showHighlights configuration option.

Both of these work without the sidebar app's involvement.

Copy link
Contributor

@nickstenning nickstenning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good. Couple of points to address inline.

@@ -272,6 +272,17 @@ function annotationExists(state, id) {
});
}

function findIDsForTags(state, tags) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of things here:

  • This needs a doc comment.
  • findByTag and findByID both have the signature (annotations, XXX) rather than (state, XXX), and this should probably be the same.
  • This should probably live next to findByTag and findByID?

More generally, I'm still concerned that we keep adding O(N^2) lookup functions... this is just going to come and bite us in the future on pages with lots of annotations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably live next to findByTag and findByID?

This function takes the global state object for consistency with the other selector functions (in this module and others) which are exported from the module (see the functions just above this one). findByTag and findByID are local helpers.

More generally, I'm still concerned that we keep adding O(N^2) lookup functions...

In this PR, I'm just moving this function here from WidgetController.

Until recently, there was no single unique key for annotations, but now we guarantee that every annotation has a unique local tag as soon as it is added to the store, so we could now replace the annotations array with a tag => Annotation map and then maintain a separate ID => tag map for example.

@@ -52,8 +53,14 @@ describe('FrameSync', function () {
});

beforeEach(function () {
fakeAnnotationUI = fakeStore({annotations: []});
fakeAnnotationUI.updateAnchorStatus = sinon.stub();
fakeAnnotationUI = fakeStore({annotations: []}, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Question. Is there any reason we couldn't use the real store here? Surely the whole point of a redux store is that it has no side-effects of its own, so we could just use the real thing and stub out specific methods if we wanted to ensure they were called correctly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core (state, action) => state function has no side effects, but the actual dispatch function does because of middleware which does things like trigger an Angular $digest cycle after each update (and in future, we may also use this as a place to capture metrics, capture errors etc.)

Copy link
Contributor

@sheetaluk sheetaluk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selecting a highlight in the document gives me the following console error:
frame-sync.js:121 Uncaught TypeError: annotationUI.findIDsForTags is not a function

I get the same error when I click on one of the bucket indicators in the bucket bar.

Also, hovering on an annotation highlight doesn't seem to do anything.

@robertknight robertknight force-pushed the remove-annotation-ui-sync branch from e7d88c4 to 54789ba Compare November 7, 2016 10:42
As a step towards having all bridge event handlers in one place, move
these event handlers into frameSync.

 * Add tests for findIDsForTags() and for re-exporting of this
   function from annotationUI
Its functionality has now been moved into the FrameSync service, except
for the logic that was intended to synchronize the "Show Annotation
Highlights" logic across multiple frames, since this is clearly broken
[1].

The two pieces of functionality related to this we need to support at
the moment are:

 1. The `showHighlights` config option to set whether highlights are
    initially visible.

 2. The highlight toggle button in the sidebar's outer frame

Both of these work without the sidebar app's involvement.

[1] See hypothesis/h#3433 and
    hypothesis/h#3295
@robertknight robertknight force-pushed the remove-annotation-ui-sync branch from 54789ba to 42d9aba Compare November 8, 2016 10:54
@sheetaluk
Copy link
Contributor

LGTM.

@sheetaluk sheetaluk merged commit bb71cd7 into master Nov 8, 2016
@sheetaluk sheetaluk deleted the remove-annotation-ui-sync branch November 8, 2016 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants