From 491fb91446ceed58e506979c4a216557c27f803e Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Fri, 9 Sep 2016 00:45:49 -0700 Subject: [PATCH] Adds methods to doc and query that operate on ref data. --- firebase-database-behavior.html | 11 +++++++++++ firebase-query.html | 28 +++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/firebase-database-behavior.html b/firebase-database-behavior.html index bacdae3..af85e0d 100644 --- a/firebase-database-behavior.html +++ b/firebase-database-behavior.html @@ -51,6 +51,17 @@ '__onlineChanged(online)' ], + /** + * Remove all data at the current query location. + * + * **Note:** This will remove *all* data at the path of this + * query, regardless of whether it is visible given the current + * query parameters. + */ + remove() { + return this.ref.remove(); + }, + _setFirebaseValue: function(path, value) { this._log('Setting Firebase value at', path, 'to', value) var key = value && value.$key; diff --git a/firebase-query.html b/firebase-query.html index 7224a96..0a531e6 100644 --- a/firebase-query.html +++ b/firebase-query.html @@ -154,8 +154,34 @@ this.__queryChanged(null, this.query); }, + /** + * Returns the data of the child with the specified key. + * + * **Note:** Will return `null` for any child that is not + * matched **by the current query parameters**. + */ child: function(key) { - return this.__map[key]; + return this.__map[key] || null; + }, + + /** + * Push a new item onto the path of this query. + * + * **Note:** If the data pushed does not match current query + * parameters, it will not appear in `data`. + */ + push(data) { + return this.ref.push(data); + }, + + /** + * Remove a child by its specified key. + * + * **Note:** The child matching the specified key will be + * removed whether or not it is visible in the current query. + */ + removeChild(key) { + return this.ref.child(key).remove(); }, get isNew() {