fix(perspective): Just wait for first CategoryStore trigger to load perspective

The FocusedPerspectiveStore wants to restore a saved current perspective from disk. It needs to wait for the categories to be ready, but it doesn't necessarily need to wait for them to be synced, because it's unlikely unsynced categories are in the saved perspective and it just falls back to unified inbox.

I think there was some dead code in `_onCategoryStoreChanged` that initialized the perspective also, so I merged the two
This commit is contained in:
Ben Gotow 2016-04-11 00:09:32 -07:00
parent df44eb493d
commit 99bd3c1e69

View file

@ -9,15 +9,12 @@ class FocusedPerspectiveStore extends NylasStore
constructor: ->
@_current = MailboxPerspective.forNothing()
CategoryStore.whenCategoriesReady().then =>
@listenTo CategoryStore, @_onCategoryStoreChanged
@listenTo Actions.focusMailboxPerspective, @_onFocusPerspective
@listenTo Actions.focusDefaultMailboxPerspectiveForAccounts, @_onFocusAccounts
@listenTo CategoryStore, @_onCategoryStoreChanged
@listenTo Actions.focusMailboxPerspective, @_onFocusPerspective
@listenTo Actions.focusDefaultMailboxPerspectiveForAccounts, @_onFocusAccounts
perspective = @_initCurrentPerspective(NylasEnv.savedState.perspective)
@_setPerspective(perspective)
_initCurrentPerspective: (savedPerspective, accounts = AccountStore.accounts()) =>
_createDefaultPerspective: (savedPerspective, accounts = AccountStore.accounts()) =>
if savedPerspective
perspective = MailboxPerspective.fromJSON(savedPerspective)
if perspective
@ -32,7 +29,8 @@ class FocusedPerspectiveStore extends NylasStore
_onCategoryStoreChanged: ->
if @_current.isEqual(MailboxPerspective.forNothing())
@_setPerspective(@_defaultPerspective())
perspective = @_createDefaultPerspective(NylasEnv.savedState.perspective)
@_setPerspective(perspective)
else
accountIds = @_current.accountIds
categories = @_current.categories()