diff --git a/spec-nylas/stores/focused-content-store-spec.coffee b/spec-nylas/stores/focused-content-store-spec.coffee index 1dd554c7e..822e1f077 100644 --- a/spec-nylas/stores/focused-content-store-spec.coffee +++ b/spec-nylas/stores/focused-content-store-spec.coffee @@ -9,21 +9,21 @@ describe "FocusedContentStore", -> describe "onSetFocus", -> it "should not trigger if the thread is already focused", -> FocusedContentStore._onFocus({collection: 'thread', item: testThread}) - spyOn(FocusedContentStore, 'trigger') + spyOn(FocusedContentStore, 'triggerAfterAnimationFrame') FocusedContentStore._onFocus({collection: 'thread', item: testThread}) - expect(FocusedContentStore.trigger).not.toHaveBeenCalled() + expect(FocusedContentStore.triggerAfterAnimationFrame).not.toHaveBeenCalled() it "should not trigger if the focus is already null", -> FocusedContentStore._onFocus({collection: 'thread', item: null}) - spyOn(FocusedContentStore, 'trigger') + spyOn(FocusedContentStore, 'triggerAfterAnimationFrame') FocusedContentStore._onFocus({collection: 'thread', item: null}) - expect(FocusedContentStore.trigger).not.toHaveBeenCalled() + expect(FocusedContentStore.triggerAfterAnimationFrame).not.toHaveBeenCalled() it "should trigger otherwise", -> FocusedContentStore._onFocus({collection: 'thread', item: null}) - spyOn(FocusedContentStore, 'trigger') + spyOn(FocusedContentStore, 'triggerAfterAnimationFrame') FocusedContentStore._onFocus({collection: 'thread', item: testThread}) - expect(FocusedContentStore.trigger).toHaveBeenCalled() + expect(FocusedContentStore.triggerAfterAnimationFrame).toHaveBeenCalled() describe "threadId", -> it "should return the id of the focused thread", -> diff --git a/src/flux/stores/focused-content-store.coffee b/src/flux/stores/focused-content-store.coffee index 2691ac073..f9614f2e2 100644 --- a/src/flux/stores/focused-content-store.coffee +++ b/src/flux/stores/focused-content-store.coffee @@ -64,6 +64,10 @@ class FocusedContentStore @listenTo Actions.setFocus, @_onFocus @listenTo Actions.setCursorPosition, @_onFocusKeyboard + triggerAfterAnimationFrame: (payload) => + window.requestAnimationFrame => + @trigger(payload) + _resetInstanceVars: => @_focused = {} @_keyboardCursor = {} @@ -81,8 +85,7 @@ class FocusedContentStore return if @_keyboardCursor[collection]?.id is item?.id @_keyboardCursor[collection] = item - window.requestAnimationFrame => - @trigger({ impactsCollection: (c) -> c is collection }) + @triggerAfterAnimationFrame({ impactsCollection: (c) -> c is collection }) _onFocus: ({collection, item}) => throw new Error("focus() requires a collection") unless collection @@ -90,8 +93,7 @@ class FocusedContentStore @_focused[collection] = item @_keyboardCursor[collection] = item if item - window.requestAnimationFrame => - @trigger({ impactsCollection: (c) -> c is collection }) + @triggerAfterAnimationFrame({ impactsCollection: (c) -> c is collection }) _onWorkspaceChange: => keyboardCursorEnabled = WorkspaceStore.layoutMode() is 'list'