From 07416e5e276649bafaeda5ceb5358079f4d0a7da Mon Sep 17 00:00:00 2001 From: johnlim Date: Wed, 6 Apr 2016 15:54:08 +0800 Subject: [PATCH 1/2] Added 'firebase-loaded' event to notify clients when initial data has been loaded and can be accessed. --- firebase-query-behavior.html | 5 +++++ test/firebase-document.html | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/firebase-query-behavior.html b/firebase-query-behavior.html index 56ba739..904f1fd 100644 --- a/firebase-query-behavior.html +++ b/firebase-query-behavior.html @@ -111,6 +111,7 @@ query.on('child_removed', this._onQueryChildRemoved, this._onQueryCancel, this); query.on('child_changed', this._onQueryChildChanged, this._onQueryCancel, this); query.on('child_moved', this._onQueryChildMoved, this._onQueryCancel, this); + query.once('value', this._onInitialDataLoaded, this); }, _stopListeningToQuery: function(query) { @@ -158,6 +159,10 @@ }, { bubbles: false }); }, + _onInitialDataLoaded: function(snapshot) { + this.fire('firebase-loaded', snapshot, { bubbles: false }); + }, + _onQueryCancel: function(error) { if (error) { this._error('Firebase Error', error); diff --git a/test/firebase-document.html b/test/firebase-document.html index bae48b1..bd5ae2b 100644 --- a/test/firebase-document.html +++ b/test/firebase-document.html @@ -80,7 +80,7 @@ suite('document updating', function() { setup(function(done) { firebase = fixture('UpdateableDocument'); - waitForEvent(firebase, 'firebase-value').then(function() { + waitForEvent(firebase, 'firebase-loaded').then(function() { done(); }); }); From eb78cec22875e51c1dc88ddce6979afb7078a253 Mon Sep 17 00:00:00 2001 From: johnlim Date: Sun, 17 Apr 2016 13:24:21 +0800 Subject: [PATCH 2/2] Alternate proposal to fire a 'firebase-loaded' event so that we do not make an additional query to firebase. --- firebase-query-behavior.html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/firebase-query-behavior.html b/firebase-query-behavior.html index 904f1fd..a7dea7c 100644 --- a/firebase-query-behavior.html +++ b/firebase-query-behavior.html @@ -69,6 +69,15 @@ this.location = ''; }, + listeners: { + 'firebase-value': '_onFirebaseLoaded' + }, + + _onFirebaseLoaded: function() { + this.unlisten(this, 'firebase-value', '_onFirebaseLoaded'); + this.fire('firebase-loaded'); + }, + _localDataChanged: function(changes) { // Virtual.. }, @@ -87,7 +96,7 @@ _dataChanged: function(changes) { if (this._receivingRemoteChanges || - this._receivingLocalChanges) { + this._receivingLocalChanges) { return; } @@ -102,6 +111,7 @@ if (query) { this._listenToQuery(query); } + this.listen(this, 'firebase-value', '_onFirebaseLoaded'); }, _listenToQuery: function(query) { @@ -111,7 +121,6 @@ query.on('child_removed', this._onQueryChildRemoved, this._onQueryCancel, this); query.on('child_changed', this._onQueryChildChanged, this._onQueryCancel, this); query.on('child_moved', this._onQueryChildMoved, this._onQueryCancel, this); - query.once('value', this._onInitialDataLoaded, this); }, _stopListeningToQuery: function(query) { @@ -159,10 +168,6 @@ }, { bubbles: false }); }, - _onInitialDataLoaded: function(snapshot) { - this.fire('firebase-loaded', snapshot, { bubbles: false }); - }, - _onQueryCancel: function(error) { if (error) { this._error('Firebase Error', error);