@vueuse/firebase 9.0.0 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +19 -8
- package/index.d.ts +5 -4
- package/index.iife.js +19 -8
- package/index.iife.min.js +1 -1
- package/index.mjs +20 -9
- package/package.json +2 -2
- package/useFirestore.cjs +19 -8
- package/useFirestore.d.ts +5 -4
- package/useFirestore.iife.js +19 -8
- package/useFirestore.iife.min.js +1 -1
- package/useFirestore.mjs +20 -9
package/index.cjs
CHANGED
|
@@ -31,25 +31,36 @@ function isDocumentReference(docRef) {
|
|
|
31
31
|
var _a;
|
|
32
32
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
33
33
|
}
|
|
34
|
-
function useFirestore(
|
|
34
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
35
35
|
const {
|
|
36
36
|
errorHandler = (err) => console.error(err),
|
|
37
37
|
autoDispose = true
|
|
38
38
|
} = options;
|
|
39
|
-
|
|
39
|
+
const refOfDocRef = vueDemi.isRef(maybeDocRef) ? maybeDocRef : vueDemi.computed(() => maybeDocRef);
|
|
40
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
40
41
|
const data = vueDemi.ref(initialValue);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
let close = () => {
|
|
43
|
+
};
|
|
44
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
45
|
+
close();
|
|
46
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
47
|
+
data.value = getData(snapshot) || null;
|
|
48
|
+
}, errorHandler);
|
|
49
|
+
}, { immediate: true });
|
|
44
50
|
shared.tryOnScopeDispose(() => {
|
|
45
51
|
close();
|
|
46
52
|
});
|
|
47
53
|
return data;
|
|
48
54
|
} else {
|
|
49
55
|
const data = vueDemi.ref(initialValue);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
let close = () => {
|
|
57
|
+
};
|
|
58
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
59
|
+
close();
|
|
60
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
61
|
+
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
62
|
+
}, errorHandler);
|
|
63
|
+
}, { immediate: true });
|
|
53
64
|
if (autoDispose) {
|
|
54
65
|
shared.tryOnScopeDispose(() => {
|
|
55
66
|
close();
|
package/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as _firebase_auth from '@firebase/auth';
|
|
|
2
2
|
import { ComputedRef, Ref } from 'vue-demi';
|
|
3
3
|
import { User, Auth } from 'firebase/auth';
|
|
4
4
|
import { Query, DocumentReference, DocumentData } from 'firebase/firestore';
|
|
5
|
+
import { MaybeRef } from '@vueuse/shared';
|
|
5
6
|
import { DatabaseReference } from 'firebase/database';
|
|
6
7
|
|
|
7
8
|
interface UseFirebaseAuthOptions {
|
|
@@ -51,10 +52,10 @@ interface UseFirestoreOptions {
|
|
|
51
52
|
autoDispose?: boolean;
|
|
52
53
|
}
|
|
53
54
|
declare type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
|
|
54
|
-
declare function useFirestore<T extends DocumentData>(
|
|
55
|
-
declare function useFirestore<T extends DocumentData>(
|
|
56
|
-
declare function useFirestore<T extends DocumentData>(
|
|
57
|
-
declare function useFirestore<T extends DocumentData>(
|
|
55
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T>>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
|
|
56
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T>>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
|
|
57
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T>>, initialValue?: T | undefined, options?: UseFirestoreOptions): Ref<T | undefined | null>;
|
|
58
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T>>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
|
|
58
59
|
|
|
59
60
|
interface UseRTDBOptions {
|
|
60
61
|
autoDispose?: boolean;
|
package/index.iife.js
CHANGED
|
@@ -98,25 +98,36 @@
|
|
|
98
98
|
var _a;
|
|
99
99
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
100
100
|
}
|
|
101
|
-
function useFirestore(
|
|
101
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
102
102
|
const {
|
|
103
103
|
errorHandler = (err) => console.error(err),
|
|
104
104
|
autoDispose = true
|
|
105
105
|
} = options;
|
|
106
|
-
|
|
106
|
+
const refOfDocRef = vueDemi.isRef(maybeDocRef) ? maybeDocRef : vueDemi.computed(() => maybeDocRef);
|
|
107
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
107
108
|
const data = vueDemi.ref(initialValue);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
let close = () => {
|
|
110
|
+
};
|
|
111
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
112
|
+
close();
|
|
113
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
114
|
+
data.value = getData(snapshot) || null;
|
|
115
|
+
}, errorHandler);
|
|
116
|
+
}, { immediate: true });
|
|
111
117
|
shared.tryOnScopeDispose(() => {
|
|
112
118
|
close();
|
|
113
119
|
});
|
|
114
120
|
return data;
|
|
115
121
|
} else {
|
|
116
122
|
const data = vueDemi.ref(initialValue);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
let close = () => {
|
|
124
|
+
};
|
|
125
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
126
|
+
close();
|
|
127
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
128
|
+
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
129
|
+
}, errorHandler);
|
|
130
|
+
}, { immediate: true });
|
|
120
131
|
if (autoDispose) {
|
|
121
132
|
shared.tryOnScopeDispose(() => {
|
|
122
133
|
close();
|
package/index.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(n,e,
|
|
1
|
+
var VueDemi=function(n,e,f){if(n.install)return n;if(e)if(e.version.slice(0,4)==="2.7."){for(var t in e)n[t]=e[t];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=e,n.Vue2=e,n.version=e.version}else if(e.version.slice(0,2)==="2.")if(f){for(var t in f)n[t]=f[t];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=e,n.Vue2=e,n.version=e.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(e.version.slice(0,2)==="3."){for(var t in e)n[t]=e[t];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=e,n.Vue2=void 0,n.version=e.version,n.set=function(r,u,c){return Array.isArray(r)?(r.length=Math.max(r.length,u),r.splice(u,1,c),c):(r[u]=c,c)},n.del=function(r,u){if(Array.isArray(r)){r.splice(u,1);return}delete r[u]}}else console.error("[vue-demi] Vue version "+e.version+" is unsupported.");else console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(n,e,f,t,r){"use strict";function u(s){const o=e.ref(s.currentUser),d=e.computed(()=>!!o.value);return s.onIdTokenChanged(l=>o.value=l),{isAuthenticated:d,user:o}}function c(s){const o=s.data();return o&&Object.defineProperty(o,"id",{value:s.id.toString(),writable:!1}),o}function y(s){var o;return(((o=s.path)==null?void 0:o.match(/\//g))||[]).length%2!=0}function b(s,o=void 0,d={}){const{errorHandler:l=i=>console.error(i),autoDispose:v=!0}=d,p=e.isRef(s)?s:e.computed(()=>s);if(y(p.value)){const i=e.ref(o);let a=()=>{};return e.watch(p,h=>{a(),a=t.onSnapshot(h,A=>{i.value=c(A)||null},l)},{immediate:!0}),f.tryOnScopeDispose(()=>{a()}),i}else{const i=e.ref(o);let a=()=>{};return e.watch(p,h=>{a(),a=t.onSnapshot(h,A=>{i.value=A.docs.map(c).filter(f.isDef)},l)},{immediate:!0}),v&&f.tryOnScopeDispose(()=>{a()}),i}}function O(s,o={}){const{autoDispose:d=!0}=o,l=e.ref(void 0);function v(i){l.value=i.val()}const p=r.onValue(s,v);return d&&f.tryOnScopeDispose(()=>p()),l}n.useAuth=u,n.useFirestore=b,n.useRTDB=O,Object.defineProperty(n,"__esModule",{value:!0})})(this.VueUse=this.VueUse||{},VueDemi,VueUse,firestore,database);
|
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, computed } from 'vue-demi';
|
|
1
|
+
import { ref, computed, isRef, watch } from 'vue-demi';
|
|
2
2
|
import { tryOnScopeDispose, isDef } from '@vueuse/shared';
|
|
3
3
|
import { onSnapshot } from 'firebase/firestore';
|
|
4
4
|
import { onValue } from 'firebase/database';
|
|
@@ -27,25 +27,36 @@ function isDocumentReference(docRef) {
|
|
|
27
27
|
var _a;
|
|
28
28
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
29
29
|
}
|
|
30
|
-
function useFirestore(
|
|
30
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
31
31
|
const {
|
|
32
32
|
errorHandler = (err) => console.error(err),
|
|
33
33
|
autoDispose = true
|
|
34
34
|
} = options;
|
|
35
|
-
|
|
35
|
+
const refOfDocRef = isRef(maybeDocRef) ? maybeDocRef : computed(() => maybeDocRef);
|
|
36
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
36
37
|
const data = ref(initialValue);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
let close = () => {
|
|
39
|
+
};
|
|
40
|
+
watch(refOfDocRef, (docRef) => {
|
|
41
|
+
close();
|
|
42
|
+
close = onSnapshot(docRef, (snapshot) => {
|
|
43
|
+
data.value = getData(snapshot) || null;
|
|
44
|
+
}, errorHandler);
|
|
45
|
+
}, { immediate: true });
|
|
40
46
|
tryOnScopeDispose(() => {
|
|
41
47
|
close();
|
|
42
48
|
});
|
|
43
49
|
return data;
|
|
44
50
|
} else {
|
|
45
51
|
const data = ref(initialValue);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
let close = () => {
|
|
53
|
+
};
|
|
54
|
+
watch(refOfDocRef, (docRef) => {
|
|
55
|
+
close();
|
|
56
|
+
close = onSnapshot(docRef, (snapshot) => {
|
|
57
|
+
data.value = snapshot.docs.map(getData).filter(isDef);
|
|
58
|
+
}, errorHandler);
|
|
59
|
+
}, { immediate: true });
|
|
49
60
|
if (autoDispose) {
|
|
50
61
|
tryOnScopeDispose(() => {
|
|
51
62
|
close();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/firebase",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"description": "Enables realtime bindings for Firebase",
|
|
5
5
|
"author": "Anthony Fu <https://github.com/antfu>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"firebase": ">=9.0.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@vueuse/shared": "9.0.
|
|
57
|
+
"@vueuse/shared": "9.0.1",
|
|
58
58
|
"vue-demi": "*"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/useFirestore.cjs
CHANGED
|
@@ -20,25 +20,36 @@ function isDocumentReference(docRef) {
|
|
|
20
20
|
var _a;
|
|
21
21
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
22
22
|
}
|
|
23
|
-
function useFirestore(
|
|
23
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
24
24
|
const {
|
|
25
25
|
errorHandler = (err) => console.error(err),
|
|
26
26
|
autoDispose = true
|
|
27
27
|
} = options;
|
|
28
|
-
|
|
28
|
+
const refOfDocRef = vueDemi.isRef(maybeDocRef) ? maybeDocRef : vueDemi.computed(() => maybeDocRef);
|
|
29
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
29
30
|
const data = vueDemi.ref(initialValue);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
let close = () => {
|
|
32
|
+
};
|
|
33
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
34
|
+
close();
|
|
35
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
36
|
+
data.value = getData(snapshot) || null;
|
|
37
|
+
}, errorHandler);
|
|
38
|
+
}, { immediate: true });
|
|
33
39
|
shared.tryOnScopeDispose(() => {
|
|
34
40
|
close();
|
|
35
41
|
});
|
|
36
42
|
return data;
|
|
37
43
|
} else {
|
|
38
44
|
const data = vueDemi.ref(initialValue);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
let close = () => {
|
|
46
|
+
};
|
|
47
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
48
|
+
close();
|
|
49
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
50
|
+
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
51
|
+
}, errorHandler);
|
|
52
|
+
}, { immediate: true });
|
|
42
53
|
if (autoDispose) {
|
|
43
54
|
shared.tryOnScopeDispose(() => {
|
|
44
55
|
close();
|
package/useFirestore.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Ref } from 'vue-demi';
|
|
2
2
|
import { Query, DocumentReference, DocumentData } from 'firebase/firestore';
|
|
3
|
+
import { MaybeRef } from '@vueuse/shared';
|
|
3
4
|
|
|
4
5
|
interface UseFirestoreOptions {
|
|
5
6
|
errorHandler?: (err: Error) => void;
|
|
6
7
|
autoDispose?: boolean;
|
|
7
8
|
}
|
|
8
9
|
declare type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
|
|
9
|
-
declare function useFirestore<T extends DocumentData>(
|
|
10
|
-
declare function useFirestore<T extends DocumentData>(
|
|
11
|
-
declare function useFirestore<T extends DocumentData>(
|
|
12
|
-
declare function useFirestore<T extends DocumentData>(
|
|
10
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T>>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
|
|
11
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T>>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
|
|
12
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T>>, initialValue?: T | undefined, options?: UseFirestoreOptions): Ref<T | undefined | null>;
|
|
13
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T>>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
|
|
13
14
|
|
|
14
15
|
export { FirebaseDocRef, UseFirestoreOptions, useFirestore };
|
package/useFirestore.iife.js
CHANGED
|
@@ -88,25 +88,36 @@
|
|
|
88
88
|
var _a;
|
|
89
89
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
90
90
|
}
|
|
91
|
-
function useFirestore(
|
|
91
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
92
92
|
const {
|
|
93
93
|
errorHandler = (err) => console.error(err),
|
|
94
94
|
autoDispose = true
|
|
95
95
|
} = options;
|
|
96
|
-
|
|
96
|
+
const refOfDocRef = vueDemi.isRef(maybeDocRef) ? maybeDocRef : vueDemi.computed(() => maybeDocRef);
|
|
97
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
97
98
|
const data = vueDemi.ref(initialValue);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
let close = () => {
|
|
100
|
+
};
|
|
101
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
102
|
+
close();
|
|
103
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
104
|
+
data.value = getData(snapshot) || null;
|
|
105
|
+
}, errorHandler);
|
|
106
|
+
}, { immediate: true });
|
|
101
107
|
shared.tryOnScopeDispose(() => {
|
|
102
108
|
close();
|
|
103
109
|
});
|
|
104
110
|
return data;
|
|
105
111
|
} else {
|
|
106
112
|
const data = vueDemi.ref(initialValue);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
let close = () => {
|
|
114
|
+
};
|
|
115
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
116
|
+
close();
|
|
117
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
118
|
+
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
119
|
+
}, errorHandler);
|
|
120
|
+
}, { immediate: true });
|
|
110
121
|
if (autoDispose) {
|
|
111
122
|
shared.tryOnScopeDispose(() => {
|
|
112
123
|
close();
|
package/useFirestore.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(n,
|
|
1
|
+
var VueDemi=function(e,n,f){if(e.install)return e;if(n)if(n.version.slice(0,4)==="2.7."){for(var o in n)e[o]=n[o];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=n,e.Vue2=n,e.version=n.version}else if(n.version.slice(0,2)==="2.")if(f){for(var o in f)e[o]=f[o];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=n,e.Vue2=n,e.version=n.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(n.version.slice(0,2)==="3."){for(var o in n)e[o]=n[o];e.isVue2=!1,e.isVue3=!0,e.install=function(){},e.Vue=n,e.Vue2=void 0,e.version=n.version,e.set=function(s,t,a){return Array.isArray(s)?(s.length=Math.max(s.length,t),s.splice(t,1,a),a):(s[t]=a,a)},e.del=function(s,t){if(Array.isArray(s)){s.splice(t,1);return}delete s[t]}}else console.error("[vue-demi] Vue version "+n.version+" is unsupported.");else console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.");return e}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(e,n,f,o){"use strict";function s(i){const r=i.data();return r&&Object.defineProperty(r,"id",{value:i.id.toString(),writable:!1}),r}function t(i){var r;return(((r=i.path)==null?void 0:r.match(/\//g))||[]).length%2!=0}function a(i,r=void 0,h={}){const{errorHandler:v=l=>console.error(l),autoDispose:y=!0}=h,u=n.isRef(i)?i:n.computed(()=>i);if(t(u.value)){const l=n.ref(r);let c=()=>{};return n.watch(u,d=>{c(),c=o.onSnapshot(d,p=>{l.value=s(p)||null},v)},{immediate:!0}),f.tryOnScopeDispose(()=>{c()}),l}else{const l=n.ref(r);let c=()=>{};return n.watch(u,d=>{c(),c=o.onSnapshot(d,p=>{l.value=p.docs.map(s).filter(f.isDef)},v)},{immediate:!0}),y&&f.tryOnScopeDispose(()=>{c()}),l}}e.useFirestore=a,Object.defineProperty(e,"__esModule",{value:!0})})(this.VueUse=this.VueUse||{},VueDemi,VueUse,firestore);
|
package/useFirestore.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref } from 'vue-demi';
|
|
1
|
+
import { isRef, computed, ref, watch } from 'vue-demi';
|
|
2
2
|
import { tryOnScopeDispose, isDef } from '@vueuse/shared';
|
|
3
3
|
import { onSnapshot } from 'firebase/firestore';
|
|
4
4
|
|
|
@@ -16,25 +16,36 @@ function isDocumentReference(docRef) {
|
|
|
16
16
|
var _a;
|
|
17
17
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
18
18
|
}
|
|
19
|
-
function useFirestore(
|
|
19
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
20
20
|
const {
|
|
21
21
|
errorHandler = (err) => console.error(err),
|
|
22
22
|
autoDispose = true
|
|
23
23
|
} = options;
|
|
24
|
-
|
|
24
|
+
const refOfDocRef = isRef(maybeDocRef) ? maybeDocRef : computed(() => maybeDocRef);
|
|
25
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
25
26
|
const data = ref(initialValue);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
let close = () => {
|
|
28
|
+
};
|
|
29
|
+
watch(refOfDocRef, (docRef) => {
|
|
30
|
+
close();
|
|
31
|
+
close = onSnapshot(docRef, (snapshot) => {
|
|
32
|
+
data.value = getData(snapshot) || null;
|
|
33
|
+
}, errorHandler);
|
|
34
|
+
}, { immediate: true });
|
|
29
35
|
tryOnScopeDispose(() => {
|
|
30
36
|
close();
|
|
31
37
|
});
|
|
32
38
|
return data;
|
|
33
39
|
} else {
|
|
34
40
|
const data = ref(initialValue);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
let close = () => {
|
|
42
|
+
};
|
|
43
|
+
watch(refOfDocRef, (docRef) => {
|
|
44
|
+
close();
|
|
45
|
+
close = onSnapshot(docRef, (snapshot) => {
|
|
46
|
+
data.value = snapshot.docs.map(getData).filter(isDef);
|
|
47
|
+
}, errorHandler);
|
|
48
|
+
}, { immediate: true });
|
|
38
49
|
if (autoDispose) {
|
|
39
50
|
tryOnScopeDispose(() => {
|
|
40
51
|
close();
|