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

Handle empty collections #18

Merged
merged 1 commit into from
Aug 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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