@vueuse/firebase 8.9.4 → 9.0.0-beta.2
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/README.md +3 -1
- package/index.cjs +8 -14
- package/index.d.ts +46 -71
- package/index.iife.js +8 -32
- package/index.iife.min.js +1 -1
- package/index.mjs +8 -14
- package/package.json +3 -3
- package/useAuth.cjs +1 -6
- package/useAuth.d.ts +35 -60
- package/useAuth.iife.js +1 -22
- package/useAuth.iife.min.js +1 -1
- package/useAuth.mjs +1 -6
- package/useFirestore.cjs +3 -2
- package/useFirestore.d.ts +8 -8
- package/useFirestore.iife.js +4 -20
- package/useFirestore.iife.min.js +1 -1
- package/useFirestore.mjs +3 -2
- package/useRTDB.cjs +4 -6
- package/useRTDB.d.ts +5 -6
- package/useRTDB.iife.js +5 -24
- package/useRTDB.iife.min.js +1 -1
- package/useRTDB.mjs +4 -6
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@vueuse/firebase)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Add-on of [VueUse](https://github.com/vueuse/vueuse), enables the real-time bindings for Firebase.
|
|
6
|
+
|
|
7
|
+
> ⚠️ This package only work with [Firebase 9 or above with the modular style](https://firebase.google.com/docs/web/modular-upgrade). For legacy versions, use `@vueuse/firebase@8` instead.
|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
package/index.cjs
CHANGED
|
@@ -4,13 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var vueDemi = require('vue-demi');
|
|
6
6
|
var shared = require('@vueuse/shared');
|
|
7
|
+
var firestore = require('firebase/firestore');
|
|
8
|
+
var database = require('firebase/database');
|
|
7
9
|
|
|
8
|
-
function useAuth(
|
|
9
|
-
let auth;
|
|
10
|
-
if (authInstance instanceof Function)
|
|
11
|
-
auth = authInstance();
|
|
12
|
-
else
|
|
13
|
-
auth = authInstance;
|
|
10
|
+
function useAuth(auth) {
|
|
14
11
|
const user = vueDemi.ref(auth.currentUser);
|
|
15
12
|
const isAuthenticated = vueDemi.computed(() => !!user.value);
|
|
16
13
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
|
@@ -41,7 +38,7 @@ function useFirestore(docRef, initialValue = void 0, options = {}) {
|
|
|
41
38
|
} = options;
|
|
42
39
|
if (isDocumentReference(docRef)) {
|
|
43
40
|
const data = vueDemi.ref(initialValue);
|
|
44
|
-
const close =
|
|
41
|
+
const close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
45
42
|
data.value = getData(snapshot) || null;
|
|
46
43
|
}, errorHandler);
|
|
47
44
|
shared.tryOnScopeDispose(() => {
|
|
@@ -50,7 +47,7 @@ function useFirestore(docRef, initialValue = void 0, options = {}) {
|
|
|
50
47
|
return data;
|
|
51
48
|
} else {
|
|
52
49
|
const data = vueDemi.ref(initialValue);
|
|
53
|
-
const close =
|
|
50
|
+
const close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
54
51
|
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
55
52
|
}, errorHandler);
|
|
56
53
|
if (autoDispose) {
|
|
@@ -70,12 +67,9 @@ function useRTDB(docRef, options = {}) {
|
|
|
70
67
|
function update(snapshot) {
|
|
71
68
|
data.value = snapshot.val();
|
|
72
69
|
}
|
|
73
|
-
|
|
74
|
-
if (autoDispose)
|
|
75
|
-
shared.tryOnScopeDispose(() =>
|
|
76
|
-
docRef.off("value", update);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
70
|
+
const off = database.onValue(docRef, update);
|
|
71
|
+
if (autoDispose)
|
|
72
|
+
shared.tryOnScopeDispose(() => off());
|
|
79
73
|
return data;
|
|
80
74
|
}
|
|
81
75
|
|
package/index.d.ts
CHANGED
|
@@ -1,94 +1,69 @@
|
|
|
1
|
+
import * as _firebase_auth from '@firebase/auth';
|
|
1
2
|
import { ComputedRef, Ref } from 'vue-demi';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
3
|
+
import { User, Auth } from 'firebase/auth';
|
|
4
|
+
import { Query, DocumentReference, DocumentData } from 'firebase/firestore';
|
|
5
|
+
import { DatabaseReference } from 'firebase/database';
|
|
4
6
|
|
|
5
|
-
interface
|
|
7
|
+
interface UseFirebaseAuthOptions {
|
|
6
8
|
isAuthenticated: ComputedRef<boolean>;
|
|
7
|
-
user: Ref<
|
|
9
|
+
user: Ref<User | null>;
|
|
8
10
|
}
|
|
9
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Reactive Firebase Auth binding
|
|
13
|
+
*
|
|
14
|
+
* @see https://vueuse.org/useAuth
|
|
15
|
+
*/
|
|
16
|
+
declare function useAuth(auth: Auth): {
|
|
10
17
|
isAuthenticated: ComputedRef<boolean>;
|
|
11
18
|
user: Ref<{
|
|
19
|
+
readonly emailVerified: boolean;
|
|
20
|
+
readonly isAnonymous: boolean;
|
|
21
|
+
readonly metadata: {
|
|
22
|
+
readonly creationTime?: string | undefined;
|
|
23
|
+
readonly lastSignInTime?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
readonly providerData: {
|
|
26
|
+
readonly displayName: string | null;
|
|
27
|
+
readonly email: string | null;
|
|
28
|
+
readonly phoneNumber: string | null;
|
|
29
|
+
readonly photoURL: string | null;
|
|
30
|
+
readonly providerId: string;
|
|
31
|
+
readonly uid: string;
|
|
32
|
+
}[];
|
|
33
|
+
readonly refreshToken: string;
|
|
34
|
+
readonly tenantId: string | null;
|
|
12
35
|
delete: () => Promise<void>;
|
|
13
|
-
emailVerified: boolean;
|
|
14
|
-
getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<firebase.auth.IdTokenResult>;
|
|
15
36
|
getIdToken: (forceRefresh?: boolean | undefined) => Promise<string>;
|
|
16
|
-
|
|
17
|
-
linkAndRetrieveDataWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
18
|
-
linkWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
19
|
-
linkWithPhoneNumber: (phoneNumber: string, applicationVerifier: firebase.auth.ApplicationVerifier) => Promise<firebase.auth.ConfirmationResult>;
|
|
20
|
-
linkWithPopup: (provider: firebase.auth.AuthProvider) => Promise<firebase.auth.UserCredential>;
|
|
21
|
-
linkWithRedirect: (provider: firebase.auth.AuthProvider) => Promise<void>;
|
|
22
|
-
metadata: {
|
|
23
|
-
creationTime?: string | undefined;
|
|
24
|
-
lastSignInTime?: string | undefined;
|
|
25
|
-
};
|
|
26
|
-
multiFactor: {
|
|
27
|
-
enrolledFactors: {
|
|
28
|
-
uid: string;
|
|
29
|
-
displayName?: string | null | undefined;
|
|
30
|
-
enrollmentTime: string;
|
|
31
|
-
factorId: string;
|
|
32
|
-
}[];
|
|
33
|
-
enroll: (assertion: firebase.auth.MultiFactorAssertion, displayName?: string | null | undefined) => Promise<void>;
|
|
34
|
-
getSession: () => Promise<firebase.auth.MultiFactorSession>;
|
|
35
|
-
unenroll: (option: string | firebase.auth.MultiFactorInfo) => Promise<void>;
|
|
36
|
-
};
|
|
37
|
-
phoneNumber: string | null;
|
|
38
|
-
providerData: ({
|
|
39
|
-
displayName: string | null;
|
|
40
|
-
email: string | null;
|
|
41
|
-
phoneNumber: string | null;
|
|
42
|
-
photoURL: string | null;
|
|
43
|
-
providerId: string;
|
|
44
|
-
uid: string;
|
|
45
|
-
} | null)[];
|
|
46
|
-
reauthenticateAndRetrieveDataWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
47
|
-
reauthenticateWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
48
|
-
reauthenticateWithPhoneNumber: (phoneNumber: string, applicationVerifier: firebase.auth.ApplicationVerifier) => Promise<firebase.auth.ConfirmationResult>;
|
|
49
|
-
reauthenticateWithPopup: (provider: firebase.auth.AuthProvider) => Promise<firebase.auth.UserCredential>;
|
|
50
|
-
reauthenticateWithRedirect: (provider: firebase.auth.AuthProvider) => Promise<void>;
|
|
51
|
-
refreshToken: string;
|
|
37
|
+
getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<_firebase_auth.IdTokenResult>;
|
|
52
38
|
reload: () => Promise<void>;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
updateProfile: (profile: {
|
|
61
|
-
displayName?: string | null | undefined;
|
|
62
|
-
photoURL?: string | null | undefined;
|
|
63
|
-
}) => Promise<void>;
|
|
64
|
-
verifyBeforeUpdateEmail: (newEmail: string, actionCodeSettings?: firebase.auth.ActionCodeSettings | null | undefined) => Promise<void>;
|
|
65
|
-
displayName: string | null;
|
|
66
|
-
email: string | null;
|
|
67
|
-
photoURL: string | null;
|
|
68
|
-
providerId: string;
|
|
69
|
-
uid: string;
|
|
39
|
+
toJSON: () => object;
|
|
40
|
+
readonly displayName: string | null;
|
|
41
|
+
readonly email: string | null;
|
|
42
|
+
readonly phoneNumber: string | null;
|
|
43
|
+
readonly photoURL: string | null;
|
|
44
|
+
readonly providerId: string;
|
|
45
|
+
readonly uid: string;
|
|
70
46
|
} | null>;
|
|
71
47
|
};
|
|
72
48
|
|
|
73
|
-
interface
|
|
49
|
+
interface UseFirestoreOptions {
|
|
74
50
|
errorHandler?: (err: Error) => void;
|
|
75
51
|
autoDispose?: boolean;
|
|
76
52
|
}
|
|
77
|
-
declare type FirebaseDocRef<T> =
|
|
78
|
-
declare function useFirestore<T extends
|
|
79
|
-
declare function useFirestore<T extends
|
|
80
|
-
declare function useFirestore<T extends
|
|
81
|
-
declare function useFirestore<T extends
|
|
53
|
+
declare type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
|
|
54
|
+
declare function useFirestore<T extends DocumentData>(docRef: DocumentReference<T>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
|
|
55
|
+
declare function useFirestore<T extends DocumentData>(docRef: Query<T>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
|
|
56
|
+
declare function useFirestore<T extends DocumentData>(docRef: DocumentReference<T>, initialValue?: T | undefined, options?: UseFirestoreOptions): Ref<T | undefined | null>;
|
|
57
|
+
declare function useFirestore<T extends DocumentData>(docRef: Query<T>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
|
|
82
58
|
|
|
83
|
-
interface
|
|
59
|
+
interface UseRTDBOptions {
|
|
84
60
|
autoDispose?: boolean;
|
|
85
61
|
}
|
|
86
62
|
/**
|
|
87
63
|
* Reactive Firebase Realtime Database binding.
|
|
88
64
|
*
|
|
89
|
-
* @
|
|
90
|
-
* @param options
|
|
65
|
+
* @see https://vueuse.org/useRTDB
|
|
91
66
|
*/
|
|
92
|
-
declare function useRTDB<T = any>(docRef:
|
|
67
|
+
declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined>;
|
|
93
68
|
|
|
94
|
-
export {
|
|
69
|
+
export { FirebaseDocRef, UseFirebaseAuthOptions, UseFirestoreOptions, UseRTDBOptions, useAuth, useFirestore, useRTDB };
|
package/index.iife.js
CHANGED
|
@@ -13,22 +13,6 @@
|
|
|
13
13
|
VueDemi.Vue = Vue
|
|
14
14
|
VueDemi.Vue2 = Vue
|
|
15
15
|
VueDemi.version = Vue.version
|
|
16
|
-
VueDemi.set = function(target, key, val) {
|
|
17
|
-
if (Array.isArray(target)) {
|
|
18
|
-
target.length = Math.max(target.length, key)
|
|
19
|
-
target.splice(key, 1, val)
|
|
20
|
-
return val
|
|
21
|
-
}
|
|
22
|
-
Vue.set(target, key, val)
|
|
23
|
-
return val
|
|
24
|
-
}
|
|
25
|
-
VueDemi.del = function(target, key) {
|
|
26
|
-
if (Array.isArray(target)) {
|
|
27
|
-
target.splice(key, 1)
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
Vue.delete(target, key)
|
|
31
|
-
}
|
|
32
16
|
}
|
|
33
17
|
else if (Vue.version.slice(0, 2) === '2.') {
|
|
34
18
|
if (VueCompositionAPI) {
|
|
@@ -87,15 +71,10 @@
|
|
|
87
71
|
this.VueCompositionAPI || (typeof VueCompositionAPI !== "undefined" ? VueCompositionAPI : undefined)
|
|
88
72
|
);
|
|
89
73
|
;
|
|
90
|
-
;(function (exports, vueDemi, shared) {
|
|
74
|
+
;(function (exports, vueDemi, shared, firestore, database) {
|
|
91
75
|
'use strict';
|
|
92
76
|
|
|
93
|
-
function useAuth(
|
|
94
|
-
let auth;
|
|
95
|
-
if (authInstance instanceof Function)
|
|
96
|
-
auth = authInstance();
|
|
97
|
-
else
|
|
98
|
-
auth = authInstance;
|
|
77
|
+
function useAuth(auth) {
|
|
99
78
|
const user = vueDemi.ref(auth.currentUser);
|
|
100
79
|
const isAuthenticated = vueDemi.computed(() => !!user.value);
|
|
101
80
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
|
@@ -126,7 +105,7 @@
|
|
|
126
105
|
} = options;
|
|
127
106
|
if (isDocumentReference(docRef)) {
|
|
128
107
|
const data = vueDemi.ref(initialValue);
|
|
129
|
-
const close =
|
|
108
|
+
const close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
130
109
|
data.value = getData(snapshot) || null;
|
|
131
110
|
}, errorHandler);
|
|
132
111
|
shared.tryOnScopeDispose(() => {
|
|
@@ -135,7 +114,7 @@
|
|
|
135
114
|
return data;
|
|
136
115
|
} else {
|
|
137
116
|
const data = vueDemi.ref(initialValue);
|
|
138
|
-
const close =
|
|
117
|
+
const close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
139
118
|
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
140
119
|
}, errorHandler);
|
|
141
120
|
if (autoDispose) {
|
|
@@ -155,12 +134,9 @@
|
|
|
155
134
|
function update(snapshot) {
|
|
156
135
|
data.value = snapshot.val();
|
|
157
136
|
}
|
|
158
|
-
|
|
159
|
-
if (autoDispose)
|
|
160
|
-
shared.tryOnScopeDispose(() =>
|
|
161
|
-
docRef.off("value", update);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
137
|
+
const off = database.onValue(docRef, update);
|
|
138
|
+
if (autoDispose)
|
|
139
|
+
shared.tryOnScopeDispose(() => off());
|
|
164
140
|
return data;
|
|
165
141
|
}
|
|
166
142
|
|
|
@@ -170,4 +146,4 @@
|
|
|
170
146
|
|
|
171
147
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
172
148
|
|
|
173
|
-
})(this.VueUse = this.VueUse || {}, VueDemi, VueUse);
|
|
149
|
+
})(this.VueUse = this.VueUse || {}, VueDemi, VueUse, firestore, database);
|
package/index.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(n,e,
|
|
1
|
+
var VueDemi=function(n,e,u){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(u){for(var t in u)n[t]=u[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,f,c){return Array.isArray(r)?(r.length=Math.max(r.length,f),r.splice(f,1,c),c):(r[f]=c,c)},n.del=function(r,f){if(Array.isArray(r)){r.splice(f,1);return}delete r[f]}}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,u,t,r){"use strict";function f(s){const o=e.ref(s.currentUser),a=e.computed(()=>!!o.value);return s.onIdTokenChanged(l=>o.value=l),{isAuthenticated:a,user:o}}function c(s){const o=s.data();return o&&Object.defineProperty(o,"id",{value:s.id.toString(),writable:!1}),o}function h(s){var o;return(((o=s.path)==null?void 0:o.match(/\//g))||[]).length%2!=0}function y(s,o=void 0,a={}){const{errorHandler:l=i=>console.error(i),autoDispose:p=!0}=a;if(h(s)){const i=e.ref(o),d=t.onSnapshot(s,v=>{i.value=c(v)||null},l);return u.tryOnScopeDispose(()=>{d()}),i}else{const i=e.ref(o),d=t.onSnapshot(s,v=>{i.value=v.docs.map(c).filter(u.isDef)},l);return p&&u.tryOnScopeDispose(()=>{d()}),i}}function A(s,o={}){const{autoDispose:a=!0}=o,l=e.ref(void 0);function p(d){l.value=d.val()}const i=r.onValue(s,p);return a&&u.tryOnScopeDispose(()=>i()),l}n.useAuth=f,n.useFirestore=y,n.useRTDB=A,Object.defineProperty(n,"__esModule",{value:!0})})(this.VueUse=this.VueUse||{},VueDemi,VueUse,firestore,database);
|
package/index.mjs
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { ref, computed } from 'vue-demi';
|
|
2
2
|
import { tryOnScopeDispose, isDef } from '@vueuse/shared';
|
|
3
|
+
import { onSnapshot } from 'firebase/firestore';
|
|
4
|
+
import { onValue } from 'firebase/database';
|
|
3
5
|
|
|
4
|
-
function useAuth(
|
|
5
|
-
let auth;
|
|
6
|
-
if (authInstance instanceof Function)
|
|
7
|
-
auth = authInstance();
|
|
8
|
-
else
|
|
9
|
-
auth = authInstance;
|
|
6
|
+
function useAuth(auth) {
|
|
10
7
|
const user = ref(auth.currentUser);
|
|
11
8
|
const isAuthenticated = computed(() => !!user.value);
|
|
12
9
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
|
@@ -37,7 +34,7 @@ function useFirestore(docRef, initialValue = void 0, options = {}) {
|
|
|
37
34
|
} = options;
|
|
38
35
|
if (isDocumentReference(docRef)) {
|
|
39
36
|
const data = ref(initialValue);
|
|
40
|
-
const close =
|
|
37
|
+
const close = onSnapshot(docRef, (snapshot) => {
|
|
41
38
|
data.value = getData(snapshot) || null;
|
|
42
39
|
}, errorHandler);
|
|
43
40
|
tryOnScopeDispose(() => {
|
|
@@ -46,7 +43,7 @@ function useFirestore(docRef, initialValue = void 0, options = {}) {
|
|
|
46
43
|
return data;
|
|
47
44
|
} else {
|
|
48
45
|
const data = ref(initialValue);
|
|
49
|
-
const close =
|
|
46
|
+
const close = onSnapshot(docRef, (snapshot) => {
|
|
50
47
|
data.value = snapshot.docs.map(getData).filter(isDef);
|
|
51
48
|
}, errorHandler);
|
|
52
49
|
if (autoDispose) {
|
|
@@ -66,12 +63,9 @@ function useRTDB(docRef, options = {}) {
|
|
|
66
63
|
function update(snapshot) {
|
|
67
64
|
data.value = snapshot.val();
|
|
68
65
|
}
|
|
69
|
-
docRef
|
|
70
|
-
if (autoDispose)
|
|
71
|
-
tryOnScopeDispose(() =>
|
|
72
|
-
docRef.off("value", update);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
66
|
+
const off = onValue(docRef, update);
|
|
67
|
+
if (autoDispose)
|
|
68
|
+
tryOnScopeDispose(() => off());
|
|
75
69
|
return data;
|
|
76
70
|
}
|
|
77
71
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/firebase",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-beta.2",
|
|
4
4
|
"description": "Enables realtime bindings for Firebase",
|
|
5
5
|
"author": "Anthony Fu <https://github.com/antfu>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
"jsdelivr": "./index.iife.min.js",
|
|
52
52
|
"types": "./index.d.ts",
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"firebase": ">=
|
|
54
|
+
"firebase": ">=9.0.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@vueuse/shared": "
|
|
57
|
+
"@vueuse/shared": "9.0.0-beta.2",
|
|
58
58
|
"vue-demi": "*"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/useAuth.cjs
CHANGED
|
@@ -4,12 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var vueDemi = require('vue-demi');
|
|
6
6
|
|
|
7
|
-
function useAuth(
|
|
8
|
-
let auth;
|
|
9
|
-
if (authInstance instanceof Function)
|
|
10
|
-
auth = authInstance();
|
|
11
|
-
else
|
|
12
|
-
auth = authInstance;
|
|
7
|
+
function useAuth(auth) {
|
|
13
8
|
const user = vueDemi.ref(auth.currentUser);
|
|
14
9
|
const isAuthenticated = vueDemi.computed(() => !!user.value);
|
|
15
10
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
package/useAuth.d.ts
CHANGED
|
@@ -1,72 +1,47 @@
|
|
|
1
|
+
import * as _firebase_auth from '@firebase/auth';
|
|
1
2
|
import { ComputedRef, Ref } from 'vue-demi';
|
|
2
|
-
import
|
|
3
|
+
import { User, Auth } from 'firebase/auth';
|
|
3
4
|
|
|
4
|
-
interface
|
|
5
|
+
interface UseFirebaseAuthOptions {
|
|
5
6
|
isAuthenticated: ComputedRef<boolean>;
|
|
6
|
-
user: Ref<
|
|
7
|
+
user: Ref<User | null>;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Reactive Firebase Auth binding
|
|
11
|
+
*
|
|
12
|
+
* @see https://vueuse.org/useAuth
|
|
13
|
+
*/
|
|
14
|
+
declare function useAuth(auth: Auth): {
|
|
9
15
|
isAuthenticated: ComputedRef<boolean>;
|
|
10
16
|
user: Ref<{
|
|
17
|
+
readonly emailVerified: boolean;
|
|
18
|
+
readonly isAnonymous: boolean;
|
|
19
|
+
readonly metadata: {
|
|
20
|
+
readonly creationTime?: string | undefined;
|
|
21
|
+
readonly lastSignInTime?: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
readonly providerData: {
|
|
24
|
+
readonly displayName: string | null;
|
|
25
|
+
readonly email: string | null;
|
|
26
|
+
readonly phoneNumber: string | null;
|
|
27
|
+
readonly photoURL: string | null;
|
|
28
|
+
readonly providerId: string;
|
|
29
|
+
readonly uid: string;
|
|
30
|
+
}[];
|
|
31
|
+
readonly refreshToken: string;
|
|
32
|
+
readonly tenantId: string | null;
|
|
11
33
|
delete: () => Promise<void>;
|
|
12
|
-
emailVerified: boolean;
|
|
13
|
-
getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<firebase.auth.IdTokenResult>;
|
|
14
34
|
getIdToken: (forceRefresh?: boolean | undefined) => Promise<string>;
|
|
15
|
-
|
|
16
|
-
linkAndRetrieveDataWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
17
|
-
linkWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
18
|
-
linkWithPhoneNumber: (phoneNumber: string, applicationVerifier: firebase.auth.ApplicationVerifier) => Promise<firebase.auth.ConfirmationResult>;
|
|
19
|
-
linkWithPopup: (provider: firebase.auth.AuthProvider) => Promise<firebase.auth.UserCredential>;
|
|
20
|
-
linkWithRedirect: (provider: firebase.auth.AuthProvider) => Promise<void>;
|
|
21
|
-
metadata: {
|
|
22
|
-
creationTime?: string | undefined;
|
|
23
|
-
lastSignInTime?: string | undefined;
|
|
24
|
-
};
|
|
25
|
-
multiFactor: {
|
|
26
|
-
enrolledFactors: {
|
|
27
|
-
uid: string;
|
|
28
|
-
displayName?: string | null | undefined;
|
|
29
|
-
enrollmentTime: string;
|
|
30
|
-
factorId: string;
|
|
31
|
-
}[];
|
|
32
|
-
enroll: (assertion: firebase.auth.MultiFactorAssertion, displayName?: string | null | undefined) => Promise<void>;
|
|
33
|
-
getSession: () => Promise<firebase.auth.MultiFactorSession>;
|
|
34
|
-
unenroll: (option: string | firebase.auth.MultiFactorInfo) => Promise<void>;
|
|
35
|
-
};
|
|
36
|
-
phoneNumber: string | null;
|
|
37
|
-
providerData: ({
|
|
38
|
-
displayName: string | null;
|
|
39
|
-
email: string | null;
|
|
40
|
-
phoneNumber: string | null;
|
|
41
|
-
photoURL: string | null;
|
|
42
|
-
providerId: string;
|
|
43
|
-
uid: string;
|
|
44
|
-
} | null)[];
|
|
45
|
-
reauthenticateAndRetrieveDataWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
46
|
-
reauthenticateWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
47
|
-
reauthenticateWithPhoneNumber: (phoneNumber: string, applicationVerifier: firebase.auth.ApplicationVerifier) => Promise<firebase.auth.ConfirmationResult>;
|
|
48
|
-
reauthenticateWithPopup: (provider: firebase.auth.AuthProvider) => Promise<firebase.auth.UserCredential>;
|
|
49
|
-
reauthenticateWithRedirect: (provider: firebase.auth.AuthProvider) => Promise<void>;
|
|
50
|
-
refreshToken: string;
|
|
35
|
+
getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<_firebase_auth.IdTokenResult>;
|
|
51
36
|
reload: () => Promise<void>;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
updateProfile: (profile: {
|
|
60
|
-
displayName?: string | null | undefined;
|
|
61
|
-
photoURL?: string | null | undefined;
|
|
62
|
-
}) => Promise<void>;
|
|
63
|
-
verifyBeforeUpdateEmail: (newEmail: string, actionCodeSettings?: firebase.auth.ActionCodeSettings | null | undefined) => Promise<void>;
|
|
64
|
-
displayName: string | null;
|
|
65
|
-
email: string | null;
|
|
66
|
-
photoURL: string | null;
|
|
67
|
-
providerId: string;
|
|
68
|
-
uid: string;
|
|
37
|
+
toJSON: () => object;
|
|
38
|
+
readonly displayName: string | null;
|
|
39
|
+
readonly email: string | null;
|
|
40
|
+
readonly phoneNumber: string | null;
|
|
41
|
+
readonly photoURL: string | null;
|
|
42
|
+
readonly providerId: string;
|
|
43
|
+
readonly uid: string;
|
|
69
44
|
} | null>;
|
|
70
45
|
};
|
|
71
46
|
|
|
72
|
-
export {
|
|
47
|
+
export { UseFirebaseAuthOptions, useAuth };
|
package/useAuth.iife.js
CHANGED
|
@@ -13,22 +13,6 @@
|
|
|
13
13
|
VueDemi.Vue = Vue
|
|
14
14
|
VueDemi.Vue2 = Vue
|
|
15
15
|
VueDemi.version = Vue.version
|
|
16
|
-
VueDemi.set = function(target, key, val) {
|
|
17
|
-
if (Array.isArray(target)) {
|
|
18
|
-
target.length = Math.max(target.length, key)
|
|
19
|
-
target.splice(key, 1, val)
|
|
20
|
-
return val
|
|
21
|
-
}
|
|
22
|
-
Vue.set(target, key, val)
|
|
23
|
-
return val
|
|
24
|
-
}
|
|
25
|
-
VueDemi.del = function(target, key) {
|
|
26
|
-
if (Array.isArray(target)) {
|
|
27
|
-
target.splice(key, 1)
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
Vue.delete(target, key)
|
|
31
|
-
}
|
|
32
16
|
}
|
|
33
17
|
else if (Vue.version.slice(0, 2) === '2.') {
|
|
34
18
|
if (VueCompositionAPI) {
|
|
@@ -90,12 +74,7 @@
|
|
|
90
74
|
;(function (exports, vueDemi) {
|
|
91
75
|
'use strict';
|
|
92
76
|
|
|
93
|
-
function useAuth(
|
|
94
|
-
let auth;
|
|
95
|
-
if (authInstance instanceof Function)
|
|
96
|
-
auth = authInstance();
|
|
97
|
-
else
|
|
98
|
-
auth = authInstance;
|
|
77
|
+
function useAuth(auth) {
|
|
99
78
|
const user = vueDemi.ref(auth.currentUser);
|
|
100
79
|
const isAuthenticated = vueDemi.computed(() => !!user.value);
|
|
101
80
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
package/useAuth.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(n,
|
|
1
|
+
var VueDemi=function(n,s,t){if(n.install)return n;if(s)if(s.version.slice(0,4)==="2.7."){for(var o in s)n[o]=s[o];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=s,n.Vue2=s,n.version=s.version}else if(s.version.slice(0,2)==="2.")if(t){for(var o in t)n[o]=t[o];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=s,n.Vue2=s,n.version=s.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(s.version.slice(0,2)==="3."){for(var o in s)n[o]=s[o];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=s,n.Vue2=void 0,n.version=s.version,n.set=function(e,r,i){return Array.isArray(e)?(e.length=Math.max(e.length,r),e.splice(r,1,i),i):(e[r]=i,i)},n.del=function(e,r){if(Array.isArray(e)){e.splice(r,1);return}delete e[r]}}else console.error("[vue-demi] Vue version "+s.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,s){"use strict";function t(o){const e=s.ref(o.currentUser),r=s.computed(()=>!!e.value);return o.onIdTokenChanged(i=>e.value=i),{isAuthenticated:r,user:e}}n.useAuth=t,Object.defineProperty(n,"__esModule",{value:!0})})(this.VueUse=this.VueUse||{},VueDemi);
|
package/useAuth.mjs
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { ref, computed } from 'vue-demi';
|
|
2
2
|
|
|
3
|
-
function useAuth(
|
|
4
|
-
let auth;
|
|
5
|
-
if (authInstance instanceof Function)
|
|
6
|
-
auth = authInstance();
|
|
7
|
-
else
|
|
8
|
-
auth = authInstance;
|
|
3
|
+
function useAuth(auth) {
|
|
9
4
|
const user = ref(auth.currentUser);
|
|
10
5
|
const isAuthenticated = computed(() => !!user.value);
|
|
11
6
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
package/useFirestore.cjs
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var vueDemi = require('vue-demi');
|
|
6
6
|
var shared = require('@vueuse/shared');
|
|
7
|
+
var firestore = require('firebase/firestore');
|
|
7
8
|
|
|
8
9
|
function getData(docRef) {
|
|
9
10
|
const data = docRef.data();
|
|
@@ -26,7 +27,7 @@ function useFirestore(docRef, initialValue = void 0, options = {}) {
|
|
|
26
27
|
} = options;
|
|
27
28
|
if (isDocumentReference(docRef)) {
|
|
28
29
|
const data = vueDemi.ref(initialValue);
|
|
29
|
-
const close =
|
|
30
|
+
const close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
30
31
|
data.value = getData(snapshot) || null;
|
|
31
32
|
}, errorHandler);
|
|
32
33
|
shared.tryOnScopeDispose(() => {
|
|
@@ -35,7 +36,7 @@ function useFirestore(docRef, initialValue = void 0, options = {}) {
|
|
|
35
36
|
return data;
|
|
36
37
|
} else {
|
|
37
38
|
const data = vueDemi.ref(initialValue);
|
|
38
|
-
const close =
|
|
39
|
+
const close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
39
40
|
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
40
41
|
}, errorHandler);
|
|
41
42
|
if (autoDispose) {
|
package/useFirestore.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import firebase from 'firebase';
|
|
2
1
|
import { Ref } from 'vue-demi';
|
|
2
|
+
import { Query, DocumentReference, DocumentData } from 'firebase/firestore';
|
|
3
3
|
|
|
4
|
-
interface
|
|
4
|
+
interface UseFirestoreOptions {
|
|
5
5
|
errorHandler?: (err: Error) => void;
|
|
6
6
|
autoDispose?: boolean;
|
|
7
7
|
}
|
|
8
|
-
declare type FirebaseDocRef<T> =
|
|
9
|
-
declare function useFirestore<T extends
|
|
10
|
-
declare function useFirestore<T extends
|
|
11
|
-
declare function useFirestore<T extends
|
|
12
|
-
declare function useFirestore<T extends
|
|
8
|
+
declare type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
|
|
9
|
+
declare function useFirestore<T extends DocumentData>(docRef: DocumentReference<T>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
|
|
10
|
+
declare function useFirestore<T extends DocumentData>(docRef: Query<T>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
|
|
11
|
+
declare function useFirestore<T extends DocumentData>(docRef: DocumentReference<T>, initialValue?: T | undefined, options?: UseFirestoreOptions): Ref<T | undefined | null>;
|
|
12
|
+
declare function useFirestore<T extends DocumentData>(docRef: Query<T>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
|
|
13
13
|
|
|
14
|
-
export { FirebaseDocRef,
|
|
14
|
+
export { FirebaseDocRef, UseFirestoreOptions, useFirestore };
|
package/useFirestore.iife.js
CHANGED
|
@@ -13,22 +13,6 @@
|
|
|
13
13
|
VueDemi.Vue = Vue
|
|
14
14
|
VueDemi.Vue2 = Vue
|
|
15
15
|
VueDemi.version = Vue.version
|
|
16
|
-
VueDemi.set = function(target, key, val) {
|
|
17
|
-
if (Array.isArray(target)) {
|
|
18
|
-
target.length = Math.max(target.length, key)
|
|
19
|
-
target.splice(key, 1, val)
|
|
20
|
-
return val
|
|
21
|
-
}
|
|
22
|
-
Vue.set(target, key, val)
|
|
23
|
-
return val
|
|
24
|
-
}
|
|
25
|
-
VueDemi.del = function(target, key) {
|
|
26
|
-
if (Array.isArray(target)) {
|
|
27
|
-
target.splice(key, 1)
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
Vue.delete(target, key)
|
|
31
|
-
}
|
|
32
16
|
}
|
|
33
17
|
else if (Vue.version.slice(0, 2) === '2.') {
|
|
34
18
|
if (VueCompositionAPI) {
|
|
@@ -87,7 +71,7 @@
|
|
|
87
71
|
this.VueCompositionAPI || (typeof VueCompositionAPI !== "undefined" ? VueCompositionAPI : undefined)
|
|
88
72
|
);
|
|
89
73
|
;
|
|
90
|
-
;(function (exports, vueDemi, shared) {
|
|
74
|
+
;(function (exports, vueDemi, shared, firestore) {
|
|
91
75
|
'use strict';
|
|
92
76
|
|
|
93
77
|
function getData(docRef) {
|
|
@@ -111,7 +95,7 @@
|
|
|
111
95
|
} = options;
|
|
112
96
|
if (isDocumentReference(docRef)) {
|
|
113
97
|
const data = vueDemi.ref(initialValue);
|
|
114
|
-
const close =
|
|
98
|
+
const close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
115
99
|
data.value = getData(snapshot) || null;
|
|
116
100
|
}, errorHandler);
|
|
117
101
|
shared.tryOnScopeDispose(() => {
|
|
@@ -120,7 +104,7 @@
|
|
|
120
104
|
return data;
|
|
121
105
|
} else {
|
|
122
106
|
const data = vueDemi.ref(initialValue);
|
|
123
|
-
const close =
|
|
107
|
+
const close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
124
108
|
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
125
109
|
}, errorHandler);
|
|
126
110
|
if (autoDispose) {
|
|
@@ -136,4 +120,4 @@
|
|
|
136
120
|
|
|
137
121
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
138
122
|
|
|
139
|
-
})(this.VueUse = this.VueUse || {}, VueDemi, VueUse);
|
|
123
|
+
})(this.VueUse = this.VueUse || {}, VueDemi, VueUse, firestore);
|
package/useFirestore.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(n,
|
|
1
|
+
var VueDemi=function(n,e,f){if(n.install)return n;if(e)if(e.version.slice(0,4)==="2.7."){for(var o in e)n[o]=e[o];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 o in f)n[o]=f[o];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 o in e)n[o]=e[o];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=e,n.Vue2=void 0,n.version=e.version,n.set=function(s,i,u){return Array.isArray(s)?(s.length=Math.max(s.length,i),s.splice(i,1,u),u):(s[i]=u,u)},n.del=function(s,i){if(Array.isArray(s)){s.splice(i,1);return}delete s[i]}}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,o){"use strict";function s(t){const r=t.data();return r&&Object.defineProperty(r,"id",{value:t.id.toString(),writable:!1}),r}function i(t){var r;return(((r=t.path)==null?void 0:r.match(/\//g))||[]).length%2!=0}function u(t,r=void 0,p={}){const{errorHandler:d=l=>console.error(l),autoDispose:v=!0}=p;if(i(t)){const l=e.ref(r),c=o.onSnapshot(t,a=>{l.value=s(a)||null},d);return f.tryOnScopeDispose(()=>{c()}),l}else{const l=e.ref(r),c=o.onSnapshot(t,a=>{l.value=a.docs.map(s).filter(f.isDef)},d);return v&&f.tryOnScopeDispose(()=>{c()}),l}}n.useFirestore=u,Object.defineProperty(n,"__esModule",{value:!0})})(this.VueUse=this.VueUse||{},VueDemi,VueUse,firestore);
|
package/useFirestore.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ref } from 'vue-demi';
|
|
2
2
|
import { tryOnScopeDispose, isDef } from '@vueuse/shared';
|
|
3
|
+
import { onSnapshot } from 'firebase/firestore';
|
|
3
4
|
|
|
4
5
|
function getData(docRef) {
|
|
5
6
|
const data = docRef.data();
|
|
@@ -22,7 +23,7 @@ function useFirestore(docRef, initialValue = void 0, options = {}) {
|
|
|
22
23
|
} = options;
|
|
23
24
|
if (isDocumentReference(docRef)) {
|
|
24
25
|
const data = ref(initialValue);
|
|
25
|
-
const close =
|
|
26
|
+
const close = onSnapshot(docRef, (snapshot) => {
|
|
26
27
|
data.value = getData(snapshot) || null;
|
|
27
28
|
}, errorHandler);
|
|
28
29
|
tryOnScopeDispose(() => {
|
|
@@ -31,7 +32,7 @@ function useFirestore(docRef, initialValue = void 0, options = {}) {
|
|
|
31
32
|
return data;
|
|
32
33
|
} else {
|
|
33
34
|
const data = ref(initialValue);
|
|
34
|
-
const close =
|
|
35
|
+
const close = onSnapshot(docRef, (snapshot) => {
|
|
35
36
|
data.value = snapshot.docs.map(getData).filter(isDef);
|
|
36
37
|
}, errorHandler);
|
|
37
38
|
if (autoDispose) {
|
package/useRTDB.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var database = require('firebase/database');
|
|
5
6
|
var vueDemi = require('vue-demi');
|
|
6
7
|
var shared = require('@vueuse/shared');
|
|
7
8
|
|
|
@@ -13,12 +14,9 @@ function useRTDB(docRef, options = {}) {
|
|
|
13
14
|
function update(snapshot) {
|
|
14
15
|
data.value = snapshot.val();
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
if (autoDispose)
|
|
18
|
-
shared.tryOnScopeDispose(() =>
|
|
19
|
-
docRef.off("value", update);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
17
|
+
const off = database.onValue(docRef, update);
|
|
18
|
+
if (autoDispose)
|
|
19
|
+
shared.tryOnScopeDispose(() => off());
|
|
22
20
|
return data;
|
|
23
21
|
}
|
|
24
22
|
|
package/useRTDB.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DatabaseReference } from 'firebase/database';
|
|
2
2
|
import { Ref } from 'vue-demi';
|
|
3
3
|
|
|
4
|
-
interface
|
|
4
|
+
interface UseRTDBOptions {
|
|
5
5
|
autoDispose?: boolean;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Reactive Firebase Realtime Database binding.
|
|
9
9
|
*
|
|
10
|
-
* @
|
|
11
|
-
* @param options
|
|
10
|
+
* @see https://vueuse.org/useRTDB
|
|
12
11
|
*/
|
|
13
|
-
declare function useRTDB<T = any>(docRef:
|
|
12
|
+
declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined>;
|
|
14
13
|
|
|
15
|
-
export {
|
|
14
|
+
export { UseRTDBOptions, useRTDB };
|
package/useRTDB.iife.js
CHANGED
|
@@ -13,22 +13,6 @@
|
|
|
13
13
|
VueDemi.Vue = Vue
|
|
14
14
|
VueDemi.Vue2 = Vue
|
|
15
15
|
VueDemi.version = Vue.version
|
|
16
|
-
VueDemi.set = function(target, key, val) {
|
|
17
|
-
if (Array.isArray(target)) {
|
|
18
|
-
target.length = Math.max(target.length, key)
|
|
19
|
-
target.splice(key, 1, val)
|
|
20
|
-
return val
|
|
21
|
-
}
|
|
22
|
-
Vue.set(target, key, val)
|
|
23
|
-
return val
|
|
24
|
-
}
|
|
25
|
-
VueDemi.del = function(target, key) {
|
|
26
|
-
if (Array.isArray(target)) {
|
|
27
|
-
target.splice(key, 1)
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
Vue.delete(target, key)
|
|
31
|
-
}
|
|
32
16
|
}
|
|
33
17
|
else if (Vue.version.slice(0, 2) === '2.') {
|
|
34
18
|
if (VueCompositionAPI) {
|
|
@@ -87,7 +71,7 @@
|
|
|
87
71
|
this.VueCompositionAPI || (typeof VueCompositionAPI !== "undefined" ? VueCompositionAPI : undefined)
|
|
88
72
|
);
|
|
89
73
|
;
|
|
90
|
-
;(function (exports, vueDemi, shared) {
|
|
74
|
+
;(function (exports, database, vueDemi, shared) {
|
|
91
75
|
'use strict';
|
|
92
76
|
|
|
93
77
|
function useRTDB(docRef, options = {}) {
|
|
@@ -98,12 +82,9 @@
|
|
|
98
82
|
function update(snapshot) {
|
|
99
83
|
data.value = snapshot.val();
|
|
100
84
|
}
|
|
101
|
-
|
|
102
|
-
if (autoDispose)
|
|
103
|
-
shared.tryOnScopeDispose(() =>
|
|
104
|
-
docRef.off("value", update);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
85
|
+
const off = database.onValue(docRef, update);
|
|
86
|
+
if (autoDispose)
|
|
87
|
+
shared.tryOnScopeDispose(() => off());
|
|
107
88
|
return data;
|
|
108
89
|
}
|
|
109
90
|
|
|
@@ -111,4 +92,4 @@
|
|
|
111
92
|
|
|
112
93
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
113
94
|
|
|
114
|
-
})(this.VueUse = this.VueUse || {}, VueDemi, VueUse);
|
|
95
|
+
})(this.VueUse = this.VueUse || {}, database, VueDemi, VueUse);
|
package/useRTDB.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(n,
|
|
1
|
+
var VueDemi=function(n,s,t){if(n.install)return n;if(s)if(s.version.slice(0,4)==="2.7."){for(var o in s)n[o]=s[o];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=s,n.Vue2=s,n.version=s.version}else if(s.version.slice(0,2)==="2.")if(t){for(var o in t)n[o]=t[o];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=s,n.Vue2=s,n.version=s.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(s.version.slice(0,2)==="3."){for(var o in s)n[o]=s[o];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=s,n.Vue2=void 0,n.version=s.version,n.set=function(e,i,r){return Array.isArray(e)?(e.length=Math.max(e.length,i),e.splice(i,1,r),r):(e[i]=r,r)},n.del=function(e,i){if(Array.isArray(e)){e.splice(i,1);return}delete e[i]}}else console.error("[vue-demi] Vue version "+s.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,s,t,o){"use strict";function e(i,r={}){const{autoDispose:l=!0}=r,f=t.ref(void 0);function u(c){f.value=c.val()}const d=s.onValue(i,u);return l&&o.tryOnScopeDispose(()=>d()),f}n.useRTDB=e,Object.defineProperty(n,"__esModule",{value:!0})})(this.VueUse=this.VueUse||{},database,VueDemi,VueUse);
|
package/useRTDB.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { onValue } from 'firebase/database';
|
|
1
2
|
import { ref } from 'vue-demi';
|
|
2
3
|
import { tryOnScopeDispose } from '@vueuse/shared';
|
|
3
4
|
|
|
@@ -9,12 +10,9 @@ function useRTDB(docRef, options = {}) {
|
|
|
9
10
|
function update(snapshot) {
|
|
10
11
|
data.value = snapshot.val();
|
|
11
12
|
}
|
|
12
|
-
docRef
|
|
13
|
-
if (autoDispose)
|
|
14
|
-
tryOnScopeDispose(() =>
|
|
15
|
-
docRef.off("value", update);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
13
|
+
const off = onValue(docRef, update);
|
|
14
|
+
if (autoDispose)
|
|
15
|
+
tryOnScopeDispose(() => off());
|
|
18
16
|
return data;
|
|
19
17
|
}
|
|
20
18
|
|