@vueuse/firebase 14.2.1 → 14.4.0
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/dist/index.d.ts +3 -3
- package/dist/index.iife.js +19 -50
- package/dist/index.iife.min.js +1 -1
- package/dist/index.js +4 -5
- package/dist/useAuth.d.ts +75 -1
- package/dist/useAuth.iife.js +6 -32
- package/dist/useAuth.iife.min.js +1 -1
- package/dist/useAuth.js +20 -3
- package/dist/useFirestore.d.ts +14 -1
- package/dist/useFirestore.iife.js +10 -38
- package/dist/useFirestore.iife.min.js +1 -1
- package/dist/useFirestore.js +49 -3
- package/dist/useRTDB.d.ts +14 -1
- package/dist/useRTDB.iife.js +8 -36
- package/dist/useRTDB.iife.min.js +1 -1
- package/dist/useRTDB.js +21 -3
- package/package.json +5 -5
- package/dist/index-C8l5U9ks.d.ts +0 -16
- package/dist/index-DNr4g7De.d.ts +0 -16
- package/dist/index-XIo_-0hT.d.ts +0 -78
- package/dist/useAuth-Cr9OEZWw.js +0 -22
- package/dist/useFirestore-BBMegHsP.js +0 -51
- package/dist/useRTDB-CCp2R9Wa.js +0 -23
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { UseFirebaseAuthOptions, useAuth } from "./useAuth.js";
|
|
2
|
+
import { FirebaseDocRef, UseFirestoreOptions, useFirestore } from "./useFirestore.js";
|
|
3
|
+
import { UseRTDBOptions, useRTDB } from "./useRTDB.js";
|
|
4
4
|
export { FirebaseDocRef, UseFirebaseAuthOptions, UseFirestoreOptions, UseRTDBOptions, useAuth, useFirestore, useRTDB };
|
package/dist/index.iife.js
CHANGED
|
@@ -1,35 +1,7 @@
|
|
|
1
|
-
(function(exports, vue,
|
|
2
|
-
|
|
3
|
-
//#region
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
-
key = keys[i];
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
-
value: mod,
|
|
22
|
-
enumerable: true
|
|
23
|
-
}) : target, mod));
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
vue = __toESM(vue);
|
|
27
|
-
__vueuse_shared = __toESM(__vueuse_shared);
|
|
28
|
-
firebase_firestore = __toESM(firebase_firestore);
|
|
29
|
-
firebase_database = __toESM(firebase_database);
|
|
30
|
-
|
|
31
|
-
//#region useAuth/index.ts
|
|
32
|
-
/**
|
|
1
|
+
(function(exports, vue, _vueuse_shared, firebase_firestore, firebase_database) {
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region useAuth/index.ts
|
|
4
|
+
/**
|
|
33
5
|
* Reactive Firebase Auth binding
|
|
34
6
|
*
|
|
35
7
|
* @see https://vueuse.org/useAuth
|
|
@@ -45,9 +17,8 @@ firebase_database = __toESM(firebase_database);
|
|
|
45
17
|
user
|
|
46
18
|
};
|
|
47
19
|
}
|
|
48
|
-
|
|
49
|
-
//#
|
|
50
|
-
//#region useFirestore/index.ts
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region useFirestore/index.ts
|
|
51
22
|
function getData(docRef) {
|
|
52
23
|
const data = docRef.data();
|
|
53
24
|
if (data) Object.defineProperty(data, "id", {
|
|
@@ -78,23 +49,22 @@ firebase_database = __toESM(firebase_database);
|
|
|
78
49
|
data.value = getData(snapshot) || null;
|
|
79
50
|
}, errorHandler);
|
|
80
51
|
else close = (0, firebase_firestore.onSnapshot)(docRef, (snapshot) => {
|
|
81
|
-
data.value = snapshot.docs.map(getData).filter(
|
|
52
|
+
data.value = snapshot.docs.map(getData).filter(_vueuse_shared.isDef);
|
|
82
53
|
}, errorHandler);
|
|
83
54
|
}, { immediate: true });
|
|
84
|
-
if (autoDispose === true) (0,
|
|
55
|
+
if (autoDispose === true) (0, _vueuse_shared.tryOnScopeDispose)(() => {
|
|
85
56
|
close();
|
|
86
57
|
});
|
|
87
|
-
else if (typeof autoDispose === "number") (0,
|
|
88
|
-
(0,
|
|
58
|
+
else if (typeof autoDispose === "number") (0, _vueuse_shared.tryOnScopeDispose)(() => {
|
|
59
|
+
(0, _vueuse_shared.useTimeoutFn)(() => {
|
|
89
60
|
close();
|
|
90
61
|
}, autoDispose);
|
|
91
62
|
});
|
|
92
63
|
return data;
|
|
93
64
|
}
|
|
94
|
-
|
|
95
|
-
//#
|
|
96
|
-
|
|
97
|
-
/**
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region useRTDB/index.ts
|
|
67
|
+
/**
|
|
98
68
|
* Reactive Firebase Realtime Database binding.
|
|
99
69
|
*
|
|
100
70
|
* @see https://vueuse.org/useRTDB
|
|
@@ -106,12 +76,11 @@ firebase_database = __toESM(firebase_database);
|
|
|
106
76
|
data.value = snapshot.val();
|
|
107
77
|
}
|
|
108
78
|
const off = (0, firebase_database.onValue)(docRef, update, errorHandler);
|
|
109
|
-
if (autoDispose) (0,
|
|
79
|
+
if (autoDispose) (0, _vueuse_shared.tryOnScopeDispose)(() => off());
|
|
110
80
|
return data;
|
|
111
81
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
exports.
|
|
115
|
-
exports.
|
|
116
|
-
|
|
117
|
-
})(this.VueUse = this.VueUse || {}, Vue, VueUse, firebase, firebase);
|
|
82
|
+
//#endregion
|
|
83
|
+
exports.useAuth = useAuth;
|
|
84
|
+
exports.useFirestore = useFirestore;
|
|
85
|
+
exports.useRTDB = useRTDB;
|
|
86
|
+
})(this.VueUse = this.VueUse || {}, Vue, VueUse, firebase, firebase);
|
package/dist/index.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t,n,r,i){
|
|
1
|
+
(function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function a(e){let n=(0,t.ref)(e.currentUser),r=(0,t.computed)(()=>!!n.value);return e.onIdTokenChanged(e=>n.value=e),{isAuthenticated:r,user:n}}function o(e){let t=e.data();return t&&Object.defineProperty(t,"id",{value:e.id.toString(),writable:!1}),t}function s(e){var t;return(((t=e.path)==null?void 0:t.match(/\//g))||[]).length%2!=0}function c(e,i=void 0,a={}){let{errorHandler:c=e=>console.error(e),autoDispose:l=!0}=a,u=(0,t.isRef)(e)?e:(0,t.computed)(()=>e),d=()=>{},f=(0,t.ref)(i);return(0,t.watch)(u,e=>{d(),u.value?d=s(u.value)?(0,r.onSnapshot)(e,e=>{f.value=o(e)||null},c):(0,r.onSnapshot)(e,e=>{f.value=e.docs.map(o).filter(n.isDef)},c):f.value=i},{immediate:!0}),l===!0?(0,n.tryOnScopeDispose)(()=>{d()}):typeof l==`number`&&(0,n.tryOnScopeDispose)(()=>{(0,n.useTimeoutFn)(()=>{d()},l)}),f}function l(e,r={}){let{errorHandler:a=e=>console.error(e),autoDispose:o=!0}=r,s=(0,t.ref)(void 0);function c(e){s.value=e.val()}let l=(0,i.onValue)(e,c,a);return o&&(0,n.tryOnScopeDispose)(()=>l()),s}e.useAuth=a,e.useFirestore=c,e.useRTDB=l})(this.VueUse=this.VueUse||{},Vue,VueUse,firebase,firebase);
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export { useAuth, useFirestore, useRTDB };
|
|
1
|
+
import { useAuth } from "./useAuth.js";
|
|
2
|
+
import { useFirestore } from "./useFirestore.js";
|
|
3
|
+
import { useRTDB } from "./useRTDB.js";
|
|
4
|
+
export { useAuth, useFirestore, useRTDB };
|
package/dist/useAuth.d.ts
CHANGED
|
@@ -1,2 +1,76 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComputedRef, Ref } from "vue";
|
|
2
|
+
import { Auth, User } from "firebase/auth";
|
|
3
|
+
//#region useAuth/index.d.ts
|
|
4
|
+
interface UseFirebaseAuthOptions {
|
|
5
|
+
isAuthenticated: ComputedRef<boolean>;
|
|
6
|
+
user: Ref<User | null>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Reactive Firebase Auth binding
|
|
10
|
+
*
|
|
11
|
+
* @see https://vueuse.org/useAuth
|
|
12
|
+
*
|
|
13
|
+
* @__NO_SIDE_EFFECTS__
|
|
14
|
+
*/
|
|
15
|
+
declare function useAuth(auth: Auth): {
|
|
16
|
+
isAuthenticated: ComputedRef<boolean>;
|
|
17
|
+
user: Ref<{
|
|
18
|
+
readonly emailVerified: boolean;
|
|
19
|
+
readonly isAnonymous: boolean;
|
|
20
|
+
readonly metadata: {
|
|
21
|
+
readonly creationTime?: string | undefined;
|
|
22
|
+
readonly lastSignInTime?: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
readonly providerData: {
|
|
25
|
+
readonly displayName: string | null;
|
|
26
|
+
readonly email: string | null;
|
|
27
|
+
readonly phoneNumber: string | null;
|
|
28
|
+
readonly photoURL: string | null;
|
|
29
|
+
readonly providerId: string;
|
|
30
|
+
readonly uid: string;
|
|
31
|
+
}[];
|
|
32
|
+
readonly refreshToken: string;
|
|
33
|
+
readonly tenantId: string | null;
|
|
34
|
+
delete: () => Promise<void>;
|
|
35
|
+
getIdToken: (forceRefresh?: boolean) => Promise<string>;
|
|
36
|
+
getIdTokenResult: (forceRefresh?: boolean) => Promise<import("firebase/auth").IdTokenResult>;
|
|
37
|
+
reload: () => Promise<void>;
|
|
38
|
+
toJSON: () => object;
|
|
39
|
+
readonly displayName: string | null;
|
|
40
|
+
readonly email: string | null;
|
|
41
|
+
readonly phoneNumber: string | null;
|
|
42
|
+
readonly photoURL: string | null;
|
|
43
|
+
readonly providerId: string;
|
|
44
|
+
readonly uid: string;
|
|
45
|
+
} | null, User | {
|
|
46
|
+
readonly emailVerified: boolean;
|
|
47
|
+
readonly isAnonymous: boolean;
|
|
48
|
+
readonly metadata: {
|
|
49
|
+
readonly creationTime?: string | undefined;
|
|
50
|
+
readonly lastSignInTime?: string | undefined;
|
|
51
|
+
};
|
|
52
|
+
readonly providerData: {
|
|
53
|
+
readonly displayName: string | null;
|
|
54
|
+
readonly email: string | null;
|
|
55
|
+
readonly phoneNumber: string | null;
|
|
56
|
+
readonly photoURL: string | null;
|
|
57
|
+
readonly providerId: string;
|
|
58
|
+
readonly uid: string;
|
|
59
|
+
}[];
|
|
60
|
+
readonly refreshToken: string;
|
|
61
|
+
readonly tenantId: string | null;
|
|
62
|
+
delete: () => Promise<void>;
|
|
63
|
+
getIdToken: (forceRefresh?: boolean) => Promise<string>;
|
|
64
|
+
getIdTokenResult: (forceRefresh?: boolean) => Promise<import("firebase/auth").IdTokenResult>;
|
|
65
|
+
reload: () => Promise<void>;
|
|
66
|
+
toJSON: () => object;
|
|
67
|
+
readonly displayName: string | null;
|
|
68
|
+
readonly email: string | null;
|
|
69
|
+
readonly phoneNumber: string | null;
|
|
70
|
+
readonly photoURL: string | null;
|
|
71
|
+
readonly providerId: string;
|
|
72
|
+
readonly uid: string;
|
|
73
|
+
} | null>;
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
2
76
|
export { UseFirebaseAuthOptions, useAuth };
|
package/dist/useAuth.iife.js
CHANGED
|
@@ -1,32 +1,7 @@
|
|
|
1
1
|
(function(exports, vue) {
|
|
2
|
-
|
|
3
|
-
//#region
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
-
key = keys[i];
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
-
value: mod,
|
|
22
|
-
enumerable: true
|
|
23
|
-
}) : target, mod));
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
vue = __toESM(vue);
|
|
27
|
-
|
|
28
|
-
//#region useAuth/index.ts
|
|
29
|
-
/**
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region useAuth/index.ts
|
|
4
|
+
/**
|
|
30
5
|
* Reactive Firebase Auth binding
|
|
31
6
|
*
|
|
32
7
|
* @see https://vueuse.org/useAuth
|
|
@@ -42,7 +17,6 @@ vue = __toESM(vue);
|
|
|
42
17
|
user
|
|
43
18
|
};
|
|
44
19
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
})(this.VueUse = this.VueUse || {}, Vue);
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.useAuth = useAuth;
|
|
22
|
+
})(this.VueUse = this.VueUse || {}, Vue);
|
package/dist/useAuth.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){
|
|
1
|
+
(function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function n(e){let n=(0,t.ref)(e.currentUser),r=(0,t.computed)(()=>!!n.value);return e.onIdTokenChanged(e=>n.value=e),{isAuthenticated:r,user:n}}e.useAuth=n})(this.VueUse=this.VueUse||{},Vue);
|
package/dist/useAuth.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
//#region useAuth/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Reactive Firebase Auth binding
|
|
5
|
+
*
|
|
6
|
+
* @see https://vueuse.org/useAuth
|
|
7
|
+
*
|
|
8
|
+
* @__NO_SIDE_EFFECTS__
|
|
9
|
+
*/
|
|
10
|
+
function useAuth(auth) {
|
|
11
|
+
const user = ref(auth.currentUser);
|
|
12
|
+
const isAuthenticated = computed(() => !!user.value);
|
|
13
|
+
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
|
14
|
+
return {
|
|
15
|
+
isAuthenticated,
|
|
16
|
+
user
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { useAuth };
|
package/dist/useFirestore.d.ts
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeRef, Ref } from "vue";
|
|
2
|
+
import { DocumentData, DocumentReference, Query } from "firebase/firestore";
|
|
3
|
+
//#region useFirestore/index.d.ts
|
|
4
|
+
interface UseFirestoreOptions {
|
|
5
|
+
errorHandler?: (err: Error) => void;
|
|
6
|
+
autoDispose?: boolean | number;
|
|
7
|
+
}
|
|
8
|
+
type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
|
|
9
|
+
type Falsy = false | 0 | '' | null | undefined;
|
|
10
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
|
|
11
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
|
|
12
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue?: T | undefined | null, options?: UseFirestoreOptions): Ref<T | undefined | null>;
|
|
13
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
|
|
14
|
+
//#endregion
|
|
2
15
|
export { FirebaseDocRef, UseFirestoreOptions, useFirestore };
|
|
@@ -1,33 +1,6 @@
|
|
|
1
|
-
(function(exports,
|
|
2
|
-
|
|
3
|
-
//#region
|
|
4
|
-
var __create = Object.create;
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
-
key = keys[i];
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
-
value: mod,
|
|
22
|
-
enumerable: true
|
|
23
|
-
}) : target, mod));
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
__vueuse_shared = __toESM(__vueuse_shared);
|
|
27
|
-
firebase_firestore = __toESM(firebase_firestore);
|
|
28
|
-
vue = __toESM(vue);
|
|
29
|
-
|
|
30
|
-
//#region useFirestore/index.ts
|
|
1
|
+
(function(exports, _vueuse_shared, firebase_firestore, vue) {
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region useFirestore/index.ts
|
|
31
4
|
function getData(docRef) {
|
|
32
5
|
const data = docRef.data();
|
|
33
6
|
if (data) Object.defineProperty(data, "id", {
|
|
@@ -58,20 +31,19 @@ vue = __toESM(vue);
|
|
|
58
31
|
data.value = getData(snapshot) || null;
|
|
59
32
|
}, errorHandler);
|
|
60
33
|
else close = (0, firebase_firestore.onSnapshot)(docRef, (snapshot) => {
|
|
61
|
-
data.value = snapshot.docs.map(getData).filter(
|
|
34
|
+
data.value = snapshot.docs.map(getData).filter(_vueuse_shared.isDef);
|
|
62
35
|
}, errorHandler);
|
|
63
36
|
}, { immediate: true });
|
|
64
|
-
if (autoDispose === true) (0,
|
|
37
|
+
if (autoDispose === true) (0, _vueuse_shared.tryOnScopeDispose)(() => {
|
|
65
38
|
close();
|
|
66
39
|
});
|
|
67
|
-
else if (typeof autoDispose === "number") (0,
|
|
68
|
-
(0,
|
|
40
|
+
else if (typeof autoDispose === "number") (0, _vueuse_shared.tryOnScopeDispose)(() => {
|
|
41
|
+
(0, _vueuse_shared.useTimeoutFn)(() => {
|
|
69
42
|
close();
|
|
70
43
|
}, autoDispose);
|
|
71
44
|
});
|
|
72
45
|
return data;
|
|
73
46
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
})(this.VueUse = this.VueUse || {}, VueUse, firebase, Vue);
|
|
47
|
+
//#endregion
|
|
48
|
+
exports.useFirestore = useFirestore;
|
|
49
|
+
})(this.VueUse = this.VueUse || {}, VueUse, firebase, Vue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t,n,r){
|
|
1
|
+
(function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e){let t=e.data();return t&&Object.defineProperty(t,"id",{value:e.id.toString(),writable:!1}),t}function a(e){var t;return(((t=e.path)==null?void 0:t.match(/\//g))||[]).length%2!=0}function o(e,o=void 0,s={}){let{errorHandler:c=e=>console.error(e),autoDispose:l=!0}=s,u=(0,r.isRef)(e)?e:(0,r.computed)(()=>e),d=()=>{},f=(0,r.ref)(o);return(0,r.watch)(u,e=>{d(),u.value?d=a(u.value)?(0,n.onSnapshot)(e,e=>{f.value=i(e)||null},c):(0,n.onSnapshot)(e,e=>{f.value=e.docs.map(i).filter(t.isDef)},c):f.value=o},{immediate:!0}),l===!0?(0,t.tryOnScopeDispose)(()=>{d()}):typeof l==`number`&&(0,t.tryOnScopeDispose)(()=>{(0,t.useTimeoutFn)(()=>{d()},l)}),f}e.useFirestore=o})(this.VueUse=this.VueUse||{},VueUse,firebase,Vue);
|
package/dist/useFirestore.js
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { computed, isRef, ref, watch } from "vue";
|
|
2
|
+
import { isDef, tryOnScopeDispose, useTimeoutFn } from "@vueuse/shared";
|
|
3
|
+
import { onSnapshot } from "firebase/firestore";
|
|
4
|
+
//#region useFirestore/index.ts
|
|
5
|
+
function getData(docRef) {
|
|
6
|
+
const data = docRef.data();
|
|
7
|
+
if (data) Object.defineProperty(data, "id", {
|
|
8
|
+
value: docRef.id.toString(),
|
|
9
|
+
writable: false
|
|
10
|
+
});
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
function isDocumentReference(docRef) {
|
|
14
|
+
var _docRef$path;
|
|
15
|
+
return (((_docRef$path = docRef.path) === null || _docRef$path === void 0 ? void 0 : _docRef$path.match(/\//g)) || []).length % 2 !== 0;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reactive Firestore binding. Making it straightforward to always keep your
|
|
19
|
+
* local data in sync with remotes databases.
|
|
20
|
+
*
|
|
21
|
+
* @see https://vueuse.org/useFirestore
|
|
22
|
+
*/
|
|
23
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
24
|
+
const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
|
|
25
|
+
const refOfDocRef = isRef(maybeDocRef) ? maybeDocRef : computed(() => maybeDocRef);
|
|
26
|
+
let close = () => {};
|
|
27
|
+
const data = ref(initialValue);
|
|
28
|
+
watch(refOfDocRef, (docRef) => {
|
|
29
|
+
close();
|
|
30
|
+
if (!refOfDocRef.value) data.value = initialValue;
|
|
31
|
+
else if (isDocumentReference(refOfDocRef.value)) close = onSnapshot(docRef, (snapshot) => {
|
|
32
|
+
data.value = getData(snapshot) || null;
|
|
33
|
+
}, errorHandler);
|
|
34
|
+
else close = onSnapshot(docRef, (snapshot) => {
|
|
35
|
+
data.value = snapshot.docs.map(getData).filter(isDef);
|
|
36
|
+
}, errorHandler);
|
|
37
|
+
}, { immediate: true });
|
|
38
|
+
if (autoDispose === true) tryOnScopeDispose(() => {
|
|
39
|
+
close();
|
|
40
|
+
});
|
|
41
|
+
else if (typeof autoDispose === "number") tryOnScopeDispose(() => {
|
|
42
|
+
useTimeoutFn(() => {
|
|
43
|
+
close();
|
|
44
|
+
}, autoDispose);
|
|
45
|
+
});
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { useFirestore };
|
package/dist/useRTDB.d.ts
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ref } from "vue";
|
|
2
|
+
import { DatabaseReference } from "firebase/database";
|
|
3
|
+
//#region useRTDB/index.d.ts
|
|
4
|
+
interface UseRTDBOptions {
|
|
5
|
+
errorHandler?: (err: Error) => void;
|
|
6
|
+
autoDispose?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Reactive Firebase Realtime Database binding.
|
|
10
|
+
*
|
|
11
|
+
* @see https://vueuse.org/useRTDB
|
|
12
|
+
*/
|
|
13
|
+
declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined, T | undefined>;
|
|
14
|
+
//#endregion
|
|
2
15
|
export { UseRTDBOptions, useRTDB };
|
package/dist/useRTDB.iife.js
CHANGED
|
@@ -1,34 +1,7 @@
|
|
|
1
|
-
(function(exports,
|
|
2
|
-
|
|
3
|
-
//#region
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
-
key = keys[i];
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
-
value: mod,
|
|
22
|
-
enumerable: true
|
|
23
|
-
}) : target, mod));
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
__vueuse_shared = __toESM(__vueuse_shared);
|
|
27
|
-
firebase_database = __toESM(firebase_database);
|
|
28
|
-
vue = __toESM(vue);
|
|
29
|
-
|
|
30
|
-
//#region useRTDB/index.ts
|
|
31
|
-
/**
|
|
1
|
+
(function(exports, _vueuse_shared, firebase_database, vue) {
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region useRTDB/index.ts
|
|
4
|
+
/**
|
|
32
5
|
* Reactive Firebase Realtime Database binding.
|
|
33
6
|
*
|
|
34
7
|
* @see https://vueuse.org/useRTDB
|
|
@@ -40,10 +13,9 @@ vue = __toESM(vue);
|
|
|
40
13
|
data.value = snapshot.val();
|
|
41
14
|
}
|
|
42
15
|
const off = (0, firebase_database.onValue)(docRef, update, errorHandler);
|
|
43
|
-
if (autoDispose) (0,
|
|
16
|
+
if (autoDispose) (0, _vueuse_shared.tryOnScopeDispose)(() => off());
|
|
44
17
|
return data;
|
|
45
18
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})(this.VueUse = this.VueUse || {}, VueUse, firebase, Vue);
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.useRTDB = useRTDB;
|
|
21
|
+
})(this.VueUse = this.VueUse || {}, VueUse, firebase, Vue);
|
package/dist/useRTDB.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t,n,r){
|
|
1
|
+
(function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e,i={}){let{errorHandler:a=e=>console.error(e),autoDispose:o=!0}=i,s=(0,r.ref)(void 0);function c(e){s.value=e.val()}let l=(0,n.onValue)(e,c,a);return o&&(0,t.tryOnScopeDispose)(()=>l()),s}e.useRTDB=i})(this.VueUse=this.VueUse||{},VueUse,firebase,Vue);
|
package/dist/useRTDB.js
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import { tryOnScopeDispose } from "@vueuse/shared";
|
|
3
|
+
import { onValue } from "firebase/database";
|
|
4
|
+
//#region useRTDB/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* Reactive Firebase Realtime Database binding.
|
|
7
|
+
*
|
|
8
|
+
* @see https://vueuse.org/useRTDB
|
|
9
|
+
*/
|
|
10
|
+
function useRTDB(docRef, options = {}) {
|
|
11
|
+
const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
|
|
12
|
+
const data = ref(void 0);
|
|
13
|
+
function update(snapshot) {
|
|
14
|
+
data.value = snapshot.val();
|
|
15
|
+
}
|
|
16
|
+
const off = onValue(docRef, update, errorHandler);
|
|
17
|
+
if (autoDispose) tryOnScopeDispose(() => off());
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { useRTDB };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/firebase",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "14.
|
|
4
|
+
"version": "14.4.0",
|
|
5
5
|
"description": "Enables realtime bindings for Firebase",
|
|
6
6
|
"author": "Anthony Fu <https://github.com/antfu>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"./*": "./dist/*",
|
|
29
29
|
"./useAuth": "./dist/useAuth.js",
|
|
30
30
|
"./useFirestore": "./dist/useFirestore.js",
|
|
31
|
-
"./useRTDB": "./dist/useRTDB.js"
|
|
31
|
+
"./useRTDB": "./dist/useRTDB.js",
|
|
32
|
+
"./package.json": "./package.json"
|
|
32
33
|
},
|
|
33
34
|
"main": "./dist/index.js",
|
|
34
35
|
"module": "./dist/index.js",
|
|
@@ -43,10 +44,9 @@
|
|
|
43
44
|
"vue": "^3.5.0"
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"@vueuse/shared": "14.
|
|
47
|
+
"@vueuse/shared": "14.4.0"
|
|
47
48
|
},
|
|
48
49
|
"scripts": {
|
|
49
|
-
"build": "tsdown"
|
|
50
|
-
"test:attw": "attw --pack --config-path ../../.attw.json ."
|
|
50
|
+
"build": "tsdown"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/dist/index-C8l5U9ks.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Ref } from "vue";
|
|
2
|
-
import { DatabaseReference } from "firebase/database";
|
|
3
|
-
|
|
4
|
-
//#region useRTDB/index.d.ts
|
|
5
|
-
interface UseRTDBOptions {
|
|
6
|
-
errorHandler?: (err: Error) => void;
|
|
7
|
-
autoDispose?: boolean;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Reactive Firebase Realtime Database binding.
|
|
11
|
-
*
|
|
12
|
-
* @see https://vueuse.org/useRTDB
|
|
13
|
-
*/
|
|
14
|
-
declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined, T | undefined>;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { useRTDB as n, UseRTDBOptions as t };
|
package/dist/index-DNr4g7De.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { MaybeRef, Ref } from "vue";
|
|
2
|
-
import { DocumentData, DocumentReference, Query } from "firebase/firestore";
|
|
3
|
-
|
|
4
|
-
//#region useFirestore/index.d.ts
|
|
5
|
-
interface UseFirestoreOptions {
|
|
6
|
-
errorHandler?: (err: Error) => void;
|
|
7
|
-
autoDispose?: boolean | number;
|
|
8
|
-
}
|
|
9
|
-
type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
|
|
10
|
-
type Falsy = false | 0 | '' | null | undefined;
|
|
11
|
-
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
|
|
12
|
-
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
|
|
13
|
-
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue?: T | undefined | null, options?: UseFirestoreOptions): Ref<T | undefined | null>;
|
|
14
|
-
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { UseFirestoreOptions as n, useFirestore as r, FirebaseDocRef as t };
|
package/dist/index-XIo_-0hT.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { ComputedRef, Ref } from "vue";
|
|
2
|
-
import * as firebase_auth0 from "firebase/auth";
|
|
3
|
-
import { Auth, User } from "firebase/auth";
|
|
4
|
-
|
|
5
|
-
//#region useAuth/index.d.ts
|
|
6
|
-
interface UseFirebaseAuthOptions {
|
|
7
|
-
isAuthenticated: ComputedRef<boolean>;
|
|
8
|
-
user: Ref<User | null>;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Reactive Firebase Auth binding
|
|
12
|
-
*
|
|
13
|
-
* @see https://vueuse.org/useAuth
|
|
14
|
-
*
|
|
15
|
-
* @__NO_SIDE_EFFECTS__
|
|
16
|
-
*/
|
|
17
|
-
declare function useAuth(auth: Auth): {
|
|
18
|
-
isAuthenticated: ComputedRef<boolean>;
|
|
19
|
-
user: Ref<{
|
|
20
|
-
readonly emailVerified: boolean;
|
|
21
|
-
readonly isAnonymous: boolean;
|
|
22
|
-
readonly metadata: {
|
|
23
|
-
readonly creationTime?: string | undefined;
|
|
24
|
-
readonly lastSignInTime?: string | undefined;
|
|
25
|
-
};
|
|
26
|
-
readonly providerData: {
|
|
27
|
-
readonly displayName: string | null;
|
|
28
|
-
readonly email: string | null;
|
|
29
|
-
readonly phoneNumber: string | null;
|
|
30
|
-
readonly photoURL: string | null;
|
|
31
|
-
readonly providerId: string;
|
|
32
|
-
readonly uid: string;
|
|
33
|
-
}[];
|
|
34
|
-
readonly refreshToken: string;
|
|
35
|
-
readonly tenantId: string | null;
|
|
36
|
-
delete: () => Promise<void>;
|
|
37
|
-
getIdToken: (forceRefresh?: boolean) => Promise<string>;
|
|
38
|
-
getIdTokenResult: (forceRefresh?: boolean) => Promise<firebase_auth0.IdTokenResult>;
|
|
39
|
-
reload: () => Promise<void>;
|
|
40
|
-
toJSON: () => object;
|
|
41
|
-
readonly displayName: string | null;
|
|
42
|
-
readonly email: string | null;
|
|
43
|
-
readonly phoneNumber: string | null;
|
|
44
|
-
readonly photoURL: string | null;
|
|
45
|
-
readonly providerId: string;
|
|
46
|
-
readonly uid: string;
|
|
47
|
-
} | null, User | {
|
|
48
|
-
readonly emailVerified: boolean;
|
|
49
|
-
readonly isAnonymous: boolean;
|
|
50
|
-
readonly metadata: {
|
|
51
|
-
readonly creationTime?: string | undefined;
|
|
52
|
-
readonly lastSignInTime?: string | undefined;
|
|
53
|
-
};
|
|
54
|
-
readonly providerData: {
|
|
55
|
-
readonly displayName: string | null;
|
|
56
|
-
readonly email: string | null;
|
|
57
|
-
readonly phoneNumber: string | null;
|
|
58
|
-
readonly photoURL: string | null;
|
|
59
|
-
readonly providerId: string;
|
|
60
|
-
readonly uid: string;
|
|
61
|
-
}[];
|
|
62
|
-
readonly refreshToken: string;
|
|
63
|
-
readonly tenantId: string | null;
|
|
64
|
-
delete: () => Promise<void>;
|
|
65
|
-
getIdToken: (forceRefresh?: boolean) => Promise<string>;
|
|
66
|
-
getIdTokenResult: (forceRefresh?: boolean) => Promise<firebase_auth0.IdTokenResult>;
|
|
67
|
-
reload: () => Promise<void>;
|
|
68
|
-
toJSON: () => object;
|
|
69
|
-
readonly displayName: string | null;
|
|
70
|
-
readonly email: string | null;
|
|
71
|
-
readonly phoneNumber: string | null;
|
|
72
|
-
readonly photoURL: string | null;
|
|
73
|
-
readonly providerId: string;
|
|
74
|
-
readonly uid: string;
|
|
75
|
-
} | null>;
|
|
76
|
-
};
|
|
77
|
-
//#endregion
|
|
78
|
-
export { useAuth as n, UseFirebaseAuthOptions as t };
|
package/dist/useAuth-Cr9OEZWw.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { computed, ref } from "vue";
|
|
2
|
-
|
|
3
|
-
//#region useAuth/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* Reactive Firebase Auth binding
|
|
6
|
-
*
|
|
7
|
-
* @see https://vueuse.org/useAuth
|
|
8
|
-
*
|
|
9
|
-
* @__NO_SIDE_EFFECTS__
|
|
10
|
-
*/
|
|
11
|
-
function useAuth(auth) {
|
|
12
|
-
const user = ref(auth.currentUser);
|
|
13
|
-
const isAuthenticated = computed(() => !!user.value);
|
|
14
|
-
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
|
15
|
-
return {
|
|
16
|
-
isAuthenticated,
|
|
17
|
-
user
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
export { useAuth as t };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { computed, isRef, ref, watch } from "vue";
|
|
2
|
-
import { isDef, tryOnScopeDispose, useTimeoutFn } from "@vueuse/shared";
|
|
3
|
-
import { onSnapshot } from "firebase/firestore";
|
|
4
|
-
|
|
5
|
-
//#region useFirestore/index.ts
|
|
6
|
-
function getData(docRef) {
|
|
7
|
-
const data = docRef.data();
|
|
8
|
-
if (data) Object.defineProperty(data, "id", {
|
|
9
|
-
value: docRef.id.toString(),
|
|
10
|
-
writable: false
|
|
11
|
-
});
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function isDocumentReference(docRef) {
|
|
15
|
-
var _docRef$path;
|
|
16
|
-
return (((_docRef$path = docRef.path) === null || _docRef$path === void 0 ? void 0 : _docRef$path.match(/\//g)) || []).length % 2 !== 0;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Reactive Firestore binding. Making it straightforward to always keep your
|
|
20
|
-
* local data in sync with remotes databases.
|
|
21
|
-
*
|
|
22
|
-
* @see https://vueuse.org/useFirestore
|
|
23
|
-
*/
|
|
24
|
-
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
25
|
-
const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
|
|
26
|
-
const refOfDocRef = isRef(maybeDocRef) ? maybeDocRef : computed(() => maybeDocRef);
|
|
27
|
-
let close = () => {};
|
|
28
|
-
const data = ref(initialValue);
|
|
29
|
-
watch(refOfDocRef, (docRef) => {
|
|
30
|
-
close();
|
|
31
|
-
if (!refOfDocRef.value) data.value = initialValue;
|
|
32
|
-
else if (isDocumentReference(refOfDocRef.value)) close = onSnapshot(docRef, (snapshot) => {
|
|
33
|
-
data.value = getData(snapshot) || null;
|
|
34
|
-
}, errorHandler);
|
|
35
|
-
else close = onSnapshot(docRef, (snapshot) => {
|
|
36
|
-
data.value = snapshot.docs.map(getData).filter(isDef);
|
|
37
|
-
}, errorHandler);
|
|
38
|
-
}, { immediate: true });
|
|
39
|
-
if (autoDispose === true) tryOnScopeDispose(() => {
|
|
40
|
-
close();
|
|
41
|
-
});
|
|
42
|
-
else if (typeof autoDispose === "number") tryOnScopeDispose(() => {
|
|
43
|
-
useTimeoutFn(() => {
|
|
44
|
-
close();
|
|
45
|
-
}, autoDispose);
|
|
46
|
-
});
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
export { useFirestore as t };
|
package/dist/useRTDB-CCp2R9Wa.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ref } from "vue";
|
|
2
|
-
import { tryOnScopeDispose } from "@vueuse/shared";
|
|
3
|
-
import { onValue } from "firebase/database";
|
|
4
|
-
|
|
5
|
-
//#region useRTDB/index.ts
|
|
6
|
-
/**
|
|
7
|
-
* Reactive Firebase Realtime Database binding.
|
|
8
|
-
*
|
|
9
|
-
* @see https://vueuse.org/useRTDB
|
|
10
|
-
*/
|
|
11
|
-
function useRTDB(docRef, options = {}) {
|
|
12
|
-
const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
|
|
13
|
-
const data = ref(void 0);
|
|
14
|
-
function update(snapshot) {
|
|
15
|
-
data.value = snapshot.val();
|
|
16
|
-
}
|
|
17
|
-
const off = onValue(docRef, update, errorHandler);
|
|
18
|
-
if (autoDispose) tryOnScopeDispose(() => off());
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
export { useRTDB as t };
|