Skip to content

Commit

Permalink
fix(discoverability): use getAnnotationMode as type existence check
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenCodes committed Sep 25, 2020
1 parent 65b5303 commit f39b0d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/store/eventing/__tests__/staged-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('store/eventing/staged', () => {
});

describe('handleSetStagedAction()', () => {
test('should not emit event if status or type is null', () => {
test('should not emit event if type is null', () => {
handleSetStagedAction(createStore().getState(), createStore().getState());

expect(eventManager.emit).not.toHaveBeenCalled();
Expand Down
11 changes: 6 additions & 5 deletions src/store/eventing/staged.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import eventManager from '../../common/EventManager';
import { getAnnotationMode } from '../common';
import { Mode } from '../common/types';
import { AppState } from '../types';
import { CreatorItem, getCreatorStaged, isCreatorStagedHighlight, isCreatorStagedRegion } from '../creator';
import { Event } from '../../@types';
Expand All @@ -7,7 +9,7 @@ type Status = 'create' | 'update' | 'cancel';

type Type = 'highlight' | 'region';

export const getStatus = (prevStaged: CreatorItem, nextStaged: CreatorItem): Status | null => {
export const getStatus = (prevStaged: CreatorItem, nextStaged: CreatorItem): Status => {
if (nextStaged === null) {
return 'cancel';
}
Expand All @@ -33,12 +35,11 @@ export const handleSetStagedAction = (prevState: AppState, nextState: AppState):
const prevStaged = getCreatorStaged(prevState);
const nextStaged = getCreatorStaged(nextState);
const status = getStatus(prevStaged, nextStaged);
const type = getType(prevStaged) || getType(nextStaged);

if (!status || !type) {
const mode = getAnnotationMode(nextState);
const type = getType(prevStaged) || getType(nextStaged) || (mode === Mode.NONE ? null : mode);
if (!type) {
return;
}

eventManager.emit(Event.CREATOR_STAGED_CHANGE, { type, status });
};

Expand Down

0 comments on commit f39b0d1

Please sign in to comment.