fix Item id / clientId issue breaking thread list

This commit is contained in:
Ben Gotow 2016-01-12 08:45:05 -08:00
parent 13870fecd5
commit b90e8abd76
2 changed files with 9 additions and 2 deletions

View file

@ -29,7 +29,7 @@ class MutableQueryResultSet extends QueryResultSet
@replaceModel(m) for m in models
addModelsInRange: (rangeModels, range) ->
@addIdsInRange(_.pluck(rangeModels, 'clientId'), range)
@addIdsInRange(_.pluck(rangeModels, 'id'), range)
@replaceModel(m) for m in rangeModels
addIdsInRange: (rangeIds, range) ->
@ -52,6 +52,7 @@ class MutableQueryResultSet extends QueryResultSet
removeModelAtOffset: (item, offset) ->
idx = offset - @_offset
delete @_modelsHash[item.clientId]
delete @_modelsHash[item.id]
@_ids.splice(idx, 1)
module.exports = MutableQueryResultSet

View file

@ -17,6 +17,12 @@ Offset vs Index:
To avoid confusion, "index" refers to an item's position in an
array, and "offset" refers to it's position in the query result set. For example,
an item might be at index 20 in the _ids array, but at offset 120 in the result.
Ids and clientIds:
QueryResultSet calways returns object `ids` when asked for ids, but lookups
for models by clientId work once models are loaded.
###
class QueryResultSet
@ -72,7 +78,7 @@ class QueryResultSet
@_modelsHash[id]
offsetOfId: (id) ->
idx = @_ids.indexOf(id)
idx = _.findIndex @models(), (m) -> m.id is id or m.clientId is id
return -1 if idx is -1
return @_offset + idx