Skip to content

Commit

Permalink
Chore: Cleanup flow types
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum committed Oct 31, 2018
1 parent a6a0903 commit fea31d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/AnnotationThread.js
Expand Up @@ -30,7 +30,7 @@ class AnnotationThread extends EventEmitter {
fileVersionId: string;

/** @param {Location} */
location: Location;
location: ?Location;

/** @param {string} */
threadID: ?string;
Expand Down Expand Up @@ -163,6 +163,7 @@ class AnnotationThread extends EventEmitter {
getPopoverParent() {
return util.shouldDisplayMobileUI(this.container)
? this.container
// $FlowFixMe
: util.getPageEl(this.annotatedElement, this.location.page);
}

Expand All @@ -172,7 +173,7 @@ class AnnotationThread extends EventEmitter {
* @param {Event} event - Mouse event
* @return {void}
*/
renderAnnotationPopover(event: Event = null) {
renderAnnotationPopover(event: ?Event = null) {
if (event) {
event.stopPropagation();
event.preventDefault();
Expand Down Expand Up @@ -662,7 +663,7 @@ class AnnotationThread extends EventEmitter {
* @param {Object} eventData - Event data
* @return {void}
*/
emit(event: Event, eventData: Object) {
emit(event: Event, eventData: ?Object) {
const threadData = this.getThreadEventData();
super.emit(event, { data: threadData, eventData });
super.emit('threadevent', { event, data: threadData, eventData });
Expand Down
35 changes: 22 additions & 13 deletions src/doc/DocHighlightThread.js
Expand Up @@ -17,12 +17,11 @@ import {
} from '../constants';

class DocHighlightThread extends AnnotationThread {
/**
* Cached page element for the document.
*
* @property {HTMLElement}
*/
pageEl;
/** @property {Location} */
location: ?Location;

/** @property {HTMLElement} */
pageEl: HTMLElement;

/**
* [constructor]
Expand Down Expand Up @@ -72,6 +71,8 @@ class DocHighlightThread extends AnnotationThread {
*/
destroy() {
this.threadID = null;

// $FlowFixMe
this.emit(THREAD_EVENT.render, this.location.page);
super.destroy();

Expand Down Expand Up @@ -108,9 +109,9 @@ class DocHighlightThread extends AnnotationThread {
* @param {string} text Text of annotation to save
* @return {void}
*/
save(type: AnnotationType, text: string) {
super.save(type, text);
save(type: AnnotationType, text: string): Promise<any> {
window.getSelection().removeAllRanges();
return super.save(type, text);
}

/**
Expand All @@ -120,14 +121,15 @@ class DocHighlightThread extends AnnotationThread {
* @param {boolean} [useServer] Whether or not to delete on server, default true
* @return {void}
*/
delete(annotation: Object, useServer: boolean = true) {
super.delete(annotation, useServer);
delete(annotation: Object, useServer: boolean = true): Promise<any> {
const promise = super.delete(annotation, useServer);

if (!this.threadID) {
return;
return promise;
}

this.renderAnnotationPopover();
return promise;
}

/**
Expand Down Expand Up @@ -284,6 +286,7 @@ class DocHighlightThread extends AnnotationThread {
scrollIntoView() {
this.scrollToPage();

// $FlowFixMe
const [yPos] = docUtil.getLowerRightCornerOfLastQuadPoint(this.location.quadPoints);

// Adjust scroll to highlight position
Expand Down Expand Up @@ -311,12 +314,14 @@ class DocHighlightThread extends AnnotationThread {
const pageHeight = pageDimensions.height - PAGE_PADDING_TOP - PAGE_PADDING_BOTTOM;
const zoomScale = util.getScale(this.annotatedElement);
const dimensionScale = util.getDimensionScale(
// $FlowFixMe
this.location.dimensions,
pageDimensions,
zoomScale,
PAGE_PADDING_TOP + PAGE_PADDING_BOTTOM
);

// $FlowFixMe
this.location.quadPoints.forEach((quadPoint) => {
// If needed, scale quad points comparing current dimensions with saved dimensions
let scaledQuadPoint = quadPoint;
Expand Down Expand Up @@ -367,6 +372,7 @@ class DocHighlightThread extends AnnotationThread {
const pageTop = pageDimensions.top + PAGE_PADDING_TOP;
const zoomScale = util.getScale(this.annotatedElement);
const dimensionScale = util.getDimensionScale(
// $FlowFixMe
this.location.dimensions,
pageDimensions,
zoomScale,
Expand All @@ -392,6 +398,7 @@ class DocHighlightThread extends AnnotationThread {

let eventOccurredInHighlight = false;

// $FlowFixMe
const points = this.location.quadPoints;
const { length } = points;

Expand Down Expand Up @@ -426,6 +433,7 @@ class DocHighlightThread extends AnnotationThread {
*/
getPageEl(): HTMLElement {
if (!this.pageEl) {
// $FlowFixMe
this.pageEl = util.getPageEl(this.annotatedElement, this.location.page);
}
return this.pageEl;
Expand All @@ -438,6 +446,7 @@ class DocHighlightThread extends AnnotationThread {
* @return {void}
*/
regenerateBoundary() {
// $FlowFixMe
if (!this.location || !this.location.quadPoints) {
return;
}
Expand Down Expand Up @@ -520,7 +529,7 @@ class DocHighlightThread extends AnnotationThread {
}

/** @inheritdoc */
cleanupAnnotationOnDelete(annotationIDToRemove: number) {
cleanupAnnotationOnDelete(annotationIDToRemove: string) {
// Delete matching comment from annotation
this.comments = this.comments.filter(({ id }) => id !== annotationIDToRemove);

Expand Down Expand Up @@ -557,7 +566,7 @@ class DocHighlightThread extends AnnotationThread {
}

/** @inheritdoc */
handleThreadSaveError(error: Error, tempAnnotationID: number) {
handleThreadSaveError(error: Error, tempAnnotationID: string) {
if (this.type === TYPES.highlight_comment && this.state === STATES.pending) {
this.type = TYPES.highlight;
this.reset();
Expand Down
1 change: 1 addition & 0 deletions src/doc/DocPointThread.js
Expand Up @@ -21,6 +21,7 @@ class DocPointThread extends AnnotationThread {
* @return {void}
*/
show() {
// $FlowFixMe
const pageEl = getPageEl(this.annotatedElement, this.location.page);
const [browserX, browserY] = getBrowserCoordinatesFromLocation(this.location, this.annotatedElement);

Expand Down

0 comments on commit fea31d1

Please sign in to comment.