Skip to content

Commit 3f46a70

Browse files
committed
fix: error handling on collections
1 parent c8355af commit 3f46a70

File tree

6 files changed

+45
-6420
lines changed

6 files changed

+45
-6420
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ node_modules
33
yarn.lock
44
package-lock.json
55
index.js
6-
index.mjs
6+
index.mjs
7+
dist/
8+
firebase-debug.log
9+
firestore-debug.log

example/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.DS_Store
22
node_modules
33
public/bundle.*
4+
firestore-debug.log
5+
firebase-debug.log

example/firebase-debug.log

Lines changed: 0 additions & 5695 deletions
This file was deleted.

example/firestore-debug.log

Lines changed: 32 additions & 717 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.0.3",
2+
"version": "0.0.4",
33
"name": "sveltefire",
44
"svelte": "src/index.js",
55
"main": "dist/index.js",
@@ -17,6 +17,7 @@
1717
"type": "git",
1818
"url": "https://github.com/codediodeio/sveltefire.git"
1919
},
20+
"publishConfig": { "registry": "https://npm.pkg.github.com/" },
2021
"devDependencies": {
2122
"concurrently": "^5.0.0",
2223
"cypress": "^3.6.1",

src/firestore.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,29 +110,28 @@ export function collectionStore(path, queryFn, opts) {
110110

111111
_teardown = (query || ref).onSnapshot(
112112
snapshot => {
113+
114+
// Will always return an array
113115
const data = snapshot.docs.map(docSnap => ({
114116
...docSnap.data(),
115117
// Allow end user override fields mapped for ID and Ref
116118
...(idField ? { [idField]: docSnap.id } : null),
117119
...(refField ? { [refField]: docSnap.ref } : null)
118120
}));
119-
const len = data.length;
121+
120122
if (log) {
121123
const type = _loading ? 'New Query' : 'Updated Query';
122-
console.groupCollapsed(`${type} ${ref.id} | ${len} hits`);
124+
console.groupCollapsed(`${type} ${ref.id} | ${data.length} hits`);
123125
console.log(`${ref.path}`);
124126
console.log(`Snapshot: `, snapshot);
125127
console.groupEnd();
126128
}
127-
128-
_error = null;
129129
next(data);
130130
},
131131

132132
error => {
133133
console.error(error);
134-
_error = error;
135-
next(null);
134+
next(null, error);
136135
}
137136
);
138137

0 commit comments

Comments
 (0)