fix(message-list): Optimize draft deletion along with draft creation

Summary:
I honestly can't wait until we refactor this logic into a sort of "LiveQuery" class so that it can apply to all of the queries in the whole app. These optimizations make deleting / creating drafts quite a bit more responsive because there's no delay between the database store emitting an event and the view updating.

Fixes T3456

No explicit tests for now because we'll pull this into a nice class soon

Test Plan: Run tests

Reviewers: dillon, evan

Reviewed By: evan

Maniphest Tasks: T3456

Differential Revision: https://phab.nylas.com/D2019
This commit is contained in:
Ben Gotow 2015-09-15 14:27:18 -07:00
parent 43e9b4cf49
commit 0289de243a

View file

@ -86,17 +86,27 @@ class MessageStore extends NylasStore
if change.objectClass is Message.name
inDisplayedThread = _.some change.objects, (obj) => obj.threadId is @_thread.id
if inDisplayedThread
return unless inDisplayedThread
if change.objects.length is 1 and change.objects[0].draft is true
item = change.objects[0]
itemAlreadyExists = _.some @_items, (msg) -> msg.id is item.id or msg.clientId is item.clientId
if change.objects.length is 1 and item.draft is true and not itemAlreadyExists
itemIndex = _.findIndex @_items, (msg) -> msg.id is item.id or msg.clientId is item.clientId
if change.type is 'persist' and itemIndex is -1
@_items = [].concat(@_items, [item])
@_items = @_sortItemsForDisplay(@_items)
@_expandItemsToDefault()
@trigger()
else
@_fetchFromCache()
return
if change.type is 'unpersist' and itemIndex isnt -1
@_items = [].concat(@_items)
@_items.splice(itemIndex, 1)
@_expandItemsToDefault()
@trigger()
return
@_fetchFromCache()
if change.objectClass is Thread.name
updatedThread = _.find change.objects, (obj) => obj.id is @_thread.id