From f39b0d1bda3bd670b0f92efe47417cbaee9791f7 Mon Sep 17 00:00:00 2001 From: Jack Chen Date: Fri, 25 Sep 2020 16:07:31 -0700 Subject: [PATCH] fix(discoverability): use getAnnotationMode as type existence check --- src/store/eventing/__tests__/staged-test.ts | 2 +- src/store/eventing/staged.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/store/eventing/__tests__/staged-test.ts b/src/store/eventing/__tests__/staged-test.ts index 3a17f9cf5..f72167380 100644 --- a/src/store/eventing/__tests__/staged-test.ts +++ b/src/store/eventing/__tests__/staged-test.ts @@ -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(); diff --git a/src/store/eventing/staged.ts b/src/store/eventing/staged.ts index 721eb3929..2d187d78f 100644 --- a/src/store/eventing/staged.ts +++ b/src/store/eventing/staged.ts @@ -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'; @@ -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'; } @@ -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 }); };