@edgedev/firebase 1.0.0 → 1.0.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/.eslintrc.json +16 -0
- package/index.ts +50 -3
- package/package.json +17 -1
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"root": true,
|
|
3
|
+
"extends": [
|
|
4
|
+
"eslint:recommended",
|
|
5
|
+
"plugin:@typescript-eslint/recommended",
|
|
6
|
+
"prettier"
|
|
7
|
+
],
|
|
8
|
+
"parser": "@typescript-eslint/parser",
|
|
9
|
+
"parserOptions": {
|
|
10
|
+
"parser": "@typescript-eslint/parser",
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"project": ["./tsconfig.json"]
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"plugins": ["@typescript-eslint"]
|
|
16
|
+
}
|
package/index.ts
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { initializeApp } from "firebase/app";
|
|
2
|
+
import { reactive } from "vue";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
getFirestore,
|
|
6
|
+
collection,
|
|
7
|
+
query,
|
|
8
|
+
onSnapshot
|
|
9
|
+
} from "firebase/firestore";
|
|
10
|
+
|
|
11
|
+
const firebaseConfig = {
|
|
12
|
+
apiKey: process.env.FIREBASE_API_KEY as string,
|
|
13
|
+
authDomain: process.env.FIREBASE_AUTH_DOMAIN as string,
|
|
14
|
+
projectId: process.env.FIREBASE_PROJECT_ID as string,
|
|
15
|
+
storageBucket: process.env.FIREBASE_STORAGE_BUCKET as string,
|
|
16
|
+
messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID as string,
|
|
17
|
+
appId: process.env.FIREBASE_APP_ID as string
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Initialize Firebase
|
|
21
|
+
const app = initializeApp(firebaseConfig);
|
|
22
|
+
const db = getFirestore(app);
|
|
23
|
+
|
|
24
|
+
// Simple Store Items (add matching key per firebase collection)
|
|
25
|
+
export const fireStoreData = reactive({});
|
|
26
|
+
export const fireStoreUnsubscibe = reactive({});
|
|
27
|
+
|
|
28
|
+
// Composable to start snapshot listener and set unsubscribe function
|
|
29
|
+
export const initSnapshot = (collectionName) => {
|
|
30
|
+
// This first "if" is to prevent multiple listeners on the same collection
|
|
31
|
+
if (!(fireStoreUnsubscibe[collectionName] instanceof Function)) {
|
|
32
|
+
const q = query(collection(db, collectionName));
|
|
33
|
+
const unsubscribe = onSnapshot(q, (querySnapshot) => {
|
|
34
|
+
const items = {};
|
|
35
|
+
querySnapshot.forEach((doc) => {
|
|
36
|
+
items[doc.id] = doc.data();
|
|
37
|
+
});
|
|
38
|
+
fireStoreData[collectionName] = items;
|
|
39
|
+
});
|
|
40
|
+
fireStoreUnsubscibe[collectionName] = unsubscribe;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Composable to stop snapshot listener
|
|
45
|
+
export const stopSnapshot = (collectionName) => {
|
|
46
|
+
if (fireStoreUnsubscibe[collectionName] instanceof Function) {
|
|
47
|
+
fireStoreUnsubscibe[collectionName]();
|
|
48
|
+
fireStoreUnsubscibe[collectionName] = null;
|
|
49
|
+
}
|
|
50
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgedev/firebase",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Composables and stores for firebase",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"author": "Seth Fischer",
|
|
@@ -8,6 +8,22 @@
|
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@types/node": "^18.11.0",
|
|
13
|
+
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
|
14
|
+
"@typescript-eslint/parser": "^5.40.0",
|
|
15
|
+
"eslint": "^8.25.0",
|
|
16
|
+
"eslint-config-prettier": "^8.5.0",
|
|
17
|
+
"prettier": "^2.7.1",
|
|
18
|
+
"typescript": "^4.8.4",
|
|
19
|
+
"vue": "^3.2.41"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"firebase": "^9.12.1"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"vue": "^3.0.0"
|
|
26
|
+
},
|
|
11
27
|
"scripts": {
|
|
12
28
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
13
29
|
}
|