Optimize offsetOfId, shouldn't throw if models contains undefined

This commit is contained in:
Ben Gotow 2016-01-20 17:27:06 -08:00
parent 6c559ddb7e
commit ffb5e0dfda

View file

@ -78,7 +78,13 @@ class QueryResultSet
@_modelsHash[id] @_modelsHash[id]
offsetOfId: (id) -> offsetOfId: (id) ->
idx = _.findIndex @models(), (m) -> m.id is id or m.clientId is id idx = @_ids.indexOf(id)
# If we can't find the item, try to match against client ids as well. Some
# items in the models() array may not be loaded, but we can try our best.
if idx is -1
idx = _.findIndex @models(), (m) -> m and (m.id is id or m.clientId is id)
return -1 if idx is -1 return -1 if idx is -1
return @_offset + idx return @_offset + idx