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

Chore: Bundling Annotators separately in annotations.js #75

Merged
merged 5 commits into from
Apr 24, 2017
Merged

Chore: Bundling Annotators separately in annotations.js #75

merged 5 commits into from
Apr 24, 2017

Conversation

pramodsum
Copy link
Contributor

@pramodsum pramodsum commented Apr 14, 2017

  • Determines which annotator to initialize based on the viewer provided in options
  • Bundles the annotators separately to reduce the size of preview.js
  • NOTE: There are still annotator methods remaining in individual viewers which will be removed in future commits

@pramodsum pramodsum changed the title Chore: Bundling Annotations separately in annotations.js Chore: Bundling Annotators separately in annotations.js Apr 14, 2017
@pramodsum
Copy link
Contributor Author

pramodsum commented Apr 18, 2017

Requires #81 to be merged first in order for all the unrelated unit tests to pass - MERGED

@@ -54,7 +54,8 @@ function updateConfig(conf, language, index) {
const config = Object.assign(conf, {
entry: {
preview: [`${lib}/Preview.js`],
csv: [`${lib}/viewers/text/BoxCSV.js`]
csv: [`${lib}/viewers/text/BoxCSV.js`],
annotations: [`${lib}/annotations/AnnotatorLoader.js`]
Copy link
Contributor

Choose a reason for hiding this comment

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

How about we call this BoxAnnotations.js? I realize it's a 'loader' similar to the viewer loaders, but this terminology may make it clearer it's a separate file and take us in the step of entirely decoupling annotations. I'd imagine we'd want to export something like BoxAnnotations.js from the future separate project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah you beat me to it!

@@ -65,8 +65,29 @@ class Annotator extends EventEmitter {
* @return {void}
*/
init() {
this._annotatedElement = this.getAnnotatedEl(this._container);
this._annotationService = this.initAnnotationService(this.options);
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably want to move away from this underscore = private syntax at some point since the rest of Preview doesn't use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do it in a separate commit so it doesn't overwhelm this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in #83

VIEWER: ['Image'],
TYPE: ['point']
}
];
Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea mirroring the viewer loaders!

/**
* Determines if this loader can be used
*
* @param {Object} viewer - Viewer
Copy link
Contributor

Choose a reason for hiding this comment

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

May be good to clarify this is the viewer info object, not an instance of a viewer. Open to ideas on how we can more clearly differentiate between the two.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clarified that we are referring to the info object here. Looking into this method more... I don't think it's explicitly used to load annotators. I might be able to actually remove this method altogether

return false;
}
return annotator.VIEWER.indexOf(viewer) > -1;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there's some combination of filter / find we can use instead of this check inside find

Copy link
Contributor

@jeremypress jeremypress Apr 18, 2017

Choose a reason for hiding this comment

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

I think this would do the same thing
return this.annotators.find(annotator => !(disabledAnnotators.includes(annotator.NAME)) && annotator.VIEWER.includes(viewer));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! Thanks!

@@ -44,6 +48,12 @@ describe('lib/annotations/doc/DocAnnotator', () => {
stubs = {};
});

describe('getAnnotatedEl()', () => {
it('should set the annotated element as the document', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd do this test as it('should return the document container as the annotated element'). You're setting annotated element explicitly in setup but that's not what getAnnotatedEl() does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops! I changed the method to return the annotated element and forgot to change the test description! Good catch thanks!

@@ -28,15 +32,16 @@ describe('lib/annotations/image/ImageAnnotator', () => {
annotator = null;
});

describe('getAnnotatedEl()', () => {
it('should set the annotated element as the document', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

STATUS_SUCCESS,
STATUS_VIEWABLE
} from '../constants';

const JS = ['annotations.js'];
Copy link
Contributor

Choose a reason for hiding this comment

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

ANNOTATIONS_JS to be clear - the other viewers include actual viewer static assets in their JS const.

@@ -255,6 +268,12 @@ class BaseViewer extends EventEmitter {
this.addListener('togglepointannotationmode', () => {
this.annotator.togglePointModeHandler();
});

this.addListener('viewerloaded', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just use load event that already exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tonyjin I actually wasn't sure if I should be using the 'load' event that already exists or not. If that's fine then i'll just use the load event rather than emitting a new one altogether

*/
initAnnotator() {
/* global AnnotatorLoader */
this.loader = new AnnotatorLoader();
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if AnnotatorLoaded is not loaded? Do we still want to have annotations NOT be loaded under the cookie switch in the WebApp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should i have it only load the AnnotatorLoader if ?showAnnotations=true is enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only loading the annotations.js file if ?showAnnotaitons=true is enabled

@@ -255,6 +268,12 @@ class BaseViewer extends EventEmitter {
this.addListener('togglepointannotationmode', () => {
this.annotator.togglePointModeHandler();
});

this.addListener('viewerloaded', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't want to hijack the load event that already gets emitted so I emitted this event instead. Does 'viewerloaded' make sense? Or should it be renamed to something else

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what you mean by hijack. Events can have multiple listeners so adding a listener to the load event won't affect other listeners as long as load is fired at time when you need it (which seems to be the case - load means the viewer has loaded content and is ready to be interact-able).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry hijack was the wrong word. Cool I'll just use the load event then! Thanks!

@@ -54,7 +54,8 @@ function updateConfig(conf, language, index) {
const config = Object.assign(conf, {
entry: {
preview: [`${lib}/Preview.js`],
csv: [`${lib}/viewers/text/BoxCSV.js`]
csv: [`${lib}/viewers/text/BoxCSV.js`],
annotations: [`${lib}/annotations/AnnotatorLoader.js`]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should this be named annotations or boxannotations?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just call it BoxAnnotations for now and rename later if needed

* @protected
* @return {void}
*/
initAnnotator() {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe change this method name since we actually init the Annotator in the initAnnotations() method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing it to loadAnnotator

@@ -218,6 +215,8 @@ class DocBaseViewer extends BaseViewer {
this.initViewer(this.pdfUrl);
this.initPrint();
this.initFind();

this.setScale(this.pdfViewer.currentScale);
Copy link
Contributor

Choose a reason for hiding this comment

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

was there a bug without this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I had added it as a part of the remaining refactoring of annotations but i'm not entirely sure why. Tested it and it doesn't seem to be related to a bug so removing it for now

@pramodsum pramodsum merged commit efa8b2a into box:master Apr 24, 2017
tonyjin added a commit that referenced this pull request Apr 29, 2017
- Revert "Fix: Ensuring annotations are loaded when viewer has permissions (#90)"
- Revert "Chore: Bundling Annotators separately in annotations.js (#75)"
- This fixes preview performance metrics based on the 'load' event
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.

3 participants