Skip to content
This repository has been archived by the owner on Jun 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #18 from grahamlyus/fix-empty-collection
Browse files Browse the repository at this point in the history
Handle empty collections
  • Loading branch information
grahamlyus authored Aug 29, 2017
2 parents 8916b05 + a2bed61 commit 4b3c66f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/restClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export default (trackedResources = [], firebaseConfig = {}, options = {}) => {

ref.on('value', function (childSnapshot) {
/** Uses "value" to fetch initial data. Avoid the AOR to show no results */
if (childSnapshot.key === resource) { resourcesData[resource] = childSnapshot.val() }
Object.keys(resourcesData[resource]).map(key => { resourcesData[resource][key].id = key })
if (childSnapshot.key === resource) { resourcesData[resource] = childSnapshot.val() || [] }
Object.keys(resourcesData[resource]).forEach(key => { resourcesData[resource][key].id = key })
ref.on('child_added', function (childSnapshot) {
resourcesData[resource][childSnapshot.key] = childSnapshot.val()
resourcesData[resource][childSnapshot.key].id = childSnapshot.key
Expand Down

0 comments on commit 4b3c66f

Please sign in to comment.