Skip to content

Commit 355e720

Browse files
committed
fix: issue on doc store showing startWith value on remove
1 parent 471fc14 commit 355e720

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1.0",
2+
"version": "0.1.1",
33
"name": "sveltefire",
44
"svelte": "src/index.js",
55
"main": "dist/index.js",

src/firestore.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ export function docStore(path, opts) {
1616

1717
// Internal state
1818
let _loading = typeof startWith !== undefined;
19+
let _firstValue = true;
1920
let _error = null;
2021
let _teardown;
2122
let _waitForIt;
2223

24+
2325
// State should never change without emitting a new value
2426
// Clears loading state on first call
2527
const next = (val, err) => {
2628
_loading = false;
29+
_firstValue = false;
2730
_waitForIt && clearTimeout(_waitForIt);
2831
_error = err || null;
2932
set(val);
@@ -40,7 +43,7 @@ export function docStore(path, opts) {
4043
// Realtime firebase subscription
4144
_teardown = ref.onSnapshot(
4245
snapshot => {
43-
const data = snapshot.data() || startWith || null;
46+
const data = snapshot.data() || (_firstValue && startWith) || null;
4447

4548
// Optional logging
4649
if (log) {

0 commit comments

Comments
 (0)