From e9eb530994c2f688610c95ed00b36bcc8b27473e Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Tue, 22 Dec 2015 13:17:22 -0800 Subject: [PATCH] fix(observables): Fix QuerySubscription to check for clientId's in result set - See TODO comments - Fixes #680 - Fixes #681 --- src/flux/models/query-subscription.coffee | 10 +++++++++- src/flux/stores/database-view.coffee | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/flux/models/query-subscription.coffee b/src/flux/models/query-subscription.coffee index 252e9dadc..010e6c0c5 100644 --- a/src/flux/models/query-subscription.coffee +++ b/src/flux/models/query-subscription.coffee @@ -125,7 +125,15 @@ class QuerySubscription endItem: @_lastResultSet[@_limit - 1] for item in items - idx = _.findIndex @_lastResultSet, ({id}) -> id is item.id + # TODO + # This logic is duplicated across DatabaseView#invalidate and + # ModelView#indexOf + # + # This duplication should go away when we refactor/replace DatabaseView + # for using observables + idx = _.findIndex @_lastResultSet, ({id, clientId}) -> + id is item.id or item.clientId is clientId + itemIsInSet = idx isnt -1 itemShouldBeInSet = item.matches(@_query.matchers()) diff --git a/src/flux/stores/database-view.coffee b/src/flux/stores/database-view.coffee index e4d05d532..916d48a7f 100644 --- a/src/flux/stores/database-view.coffee +++ b/src/flux/stores/database-view.coffee @@ -206,6 +206,13 @@ class DatabaseView extends ModelView # of the `id` then we would erroneously say that the item isn't in # the set. This happens frequently in the DraftListStore when Draft # items persist on the server and/or turn into Message items. + # + # TODO + # This logic is duplicated across QuerySubscription#_optimisticallyUpdateModels + # and ModelView#indexOf + # + # This duplication should go away when we refactor/replace DatabaseView + # for using observables idx = @indexOfId(item.clientId) itemIsInSet = idx isnt -1