Set model.id
and handle change/remove events.
#1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, the lib did not set the model.id attribute when populating a
collection from firebase. This meant that the models could not be identified
when
child_changed
orchild_removed
events came down the pipe.This commit introduces a configurable
idAttribute
, which is populated withthe firebase reference name. Implementations then need to set the
idAttribute
of their model class to use this as the source for the
model.id
value.I've updated the readme accordingly but it might be worth providing a
FirebaseModel
class that does this automatically, or generally consideringthe best implementation.
In addition, I've patched up the update and delete event handlers to get the
existing model by id (rather than trying to
collection.get(pushed_mode.val())
.