Skip to content

Commit 85733b1

Browse files
committed
✨ Support Firestore
Ported vuefire code to vuexfire codebase. This should cover most cases for the moment. Later on I should split up the code and use it in both places
1 parent 8a73fcc commit 85733b1

File tree

10 files changed

+349
-344
lines changed

10 files changed

+349
-344
lines changed

packages/vuexfire/circle.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/vuexfire/examples/TodoApp/index.html

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<head>
44
<meta charset="utf-8">
55
<title>VuexFire Todo App Demo</title>
6-
<script src="https://www.gstatic.com/firebasejs/3.7.5/firebase.js"></script>
6+
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script>
7+
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-firestore.js"></script>
78
<script src="https://unpkg.com/vue/dist/vue.js"></script>
89
<script src="https://unpkg.com/vuex/dist/vuex.js"></script>
910
<script src="../../dist/vuexfire.js"></script>
@@ -17,9 +18,9 @@
1718

1819
<div id="app">
1920
<ul>
20-
<li v-for="item in items" :key="item['.key']">
21+
<li v-for="item in items" :key="item.id">
2122
{{ item.text }}
22-
<button @click="removeTodo(item['.key'])">X</button>
23+
<button @click="removeTodo(item.id)">X</button>
2324
</li>
2425
</ul>
2526
<form @submit.prevent="addTodo">
@@ -35,26 +36,26 @@
3536

3637
<script>
3738
/* global Vue, Vuex, firebase, VuexFire */
38-
var config = {
39-
databaseURL: 'https://vuexfire.firebaseio.com',
40-
}
41-
var firebaseApp = firebase.initializeApp(config)
42-
var db = firebaseApp.database()
43-
var itemsRef = db.ref('test')
44-
var todosRef = db.ref('test_2')
39+
firebase.initializeApp({
40+
projectId: 'vue-fire-store',
41+
databaseURL: 'https://vue-fire-store.firebaseio.com'
42+
})
43+
var db = firebase.firestore()
44+
var itemsRef = db.collection('vuexfireItems1')
45+
var todosRef = db.collection('vuexfireItems2')
4546

4647
var store = new Vuex.Store({
4748
// VuexFire will check the type of the property to bind as an array or as
4849
// an object
4950
strict: true,
5051
state: { items: [] },
51-
mutations: VuexFire.firebaseMutations,
52+
mutations: Vuexfire.firebaseMutations,
5253
getters: {
5354
items: state => state.items,
5455
},
5556
actions: {
56-
setItemsRef: VuexFire.firebaseAction(({ bindFirebaseRef }, ref) => {
57-
bindFirebaseRef('items', ref, { wait: true })
57+
setItemsRef: Vuexfire.firebaseAction(({ bindFirebaseRef }, ref) => {
58+
bindFirebaseRef('items', ref)
5859
}),
5960
},
6061
})
@@ -68,12 +69,12 @@
6869
},
6970

7071
methods: {
71-
removeTodo (key) {
72-
this.source.child(key).remove()
72+
removeTodo (id) {
73+
this.source.doc(id).delete()
7374
},
7475
addTodo () {
7576
if (this.newTodo.trim()) {
76-
this.source.push({
77+
this.source.add({
7778
text: this.newTodo,
7879
})
7980
this.newTodo = ''

packages/vuexfire/examples/TodoApp/modules.html

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<head>
44
<meta charset="utf-8">
55
<title>VuexFire Todo App Demo</title>
6-
<script src="https://www.gstatic.com/firebasejs/3.7.5/firebase.js"></script>
6+
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script>
7+
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-firestore.js"></script>
78
<script src="https://unpkg.com/vue/dist/vue.js"></script>
89
<script src="https://unpkg.com/vuex/dist/vuex.js"></script>
910
<script src="../../dist/vuexfire.js"></script>
@@ -12,9 +13,9 @@
1213

1314
<div id="app">
1415
<ul>
15-
<li v-for="item in items" :key="item['.key']">
16+
<li v-for="item in items" :key="item.id">
1617
{{ item.text }}
17-
<button @click="removeTodo(item['.key'])">X</button>
18+
<button @click="removeTodo(item.id)">X</button>
1819
</li>
1920
</ul>
2021
<form @submit.prevent="addTodo">
@@ -25,27 +26,28 @@
2526

2627
<script>
2728
/* global Vue, Vuex, firebase, VuexFire */
28-
var config = {
29-
databaseURL: 'https://vuexfire.firebaseio.com',
30-
}
31-
var firebaseApp = firebase.initializeApp(config)
32-
var db = firebaseApp.database()
33-
var itemsRef = db.ref('test')
29+
firebase.initializeApp({
30+
projectId: 'vue-fire-store',
31+
databaseURL: 'https://vue-fire-store.firebaseio.com'
32+
})
33+
var db = firebase.firestore()
34+
var itemsRef = db.collection('vuexfireItems1')
3435

3536
var todos = {
3637
state: { items: [] },
37-
mutations: VuexFire.firebaseMutations,
3838
getters: {
3939
items: state => state.items,
4040
},
4141
actions: {
42-
setItemsRef: VuexFire.firebaseAction(({ bindFirebaseRef }, ref) => {
42+
setItemsRef: Vuexfire.firebaseAction(({ bindFirebaseRef }, ref) => {
4343
bindFirebaseRef('items', ref)
4444
}),
4545
},
4646
}
4747

4848
var store = new Vuex.Store({
49+
strict: true,
50+
mutations: Vuexfire.firebaseMutations,
4951
modules: { todos },
5052
})
5153

@@ -58,12 +60,12 @@
5860
},
5961

6062
methods: {
61-
removeTodo: function (key) {
62-
itemsRef.child(key).remove()
63+
removeTodo: function (id) {
64+
itemsRef.doc(id).delete()
6365
},
6466
addTodo: function () {
6567
if (this.newTodo.trim()) {
66-
itemsRef.push({
68+
itemsRef.add({
6769
text: this.newTodo,
6870
})
6971
this.newTodo = ''

packages/vuexfire/package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"name": "vuexfire",
3-
"version": "2.3.0",
3+
"version": "3.0.0-alpha.0",
44
"description": "Opinionated firebase binding for vuex",
55
"main": "dist/vuexfire.common.js",
66
"module": "dist/vuexfire.esm.js",
77
"unpkg": "dist/vuexfire.js",
88
"browser": "dist/vuexfire.js",
99
"files": [
10+
"src",
1011
"dist",
11-
"src"
12+
"LICENSE",
13+
"README.md"
1214
],
1315
"scripts": {
1416
"lint": "eslint --color --ext=js,html src test examples build",
@@ -58,14 +60,18 @@
5860
"vuex",
5961
"fire",
6062
"vue",
63+
"realtime",
64+
"database",
65+
"google",
6166
"firebase",
6267
"redux",
68+
"firestore",
6369
"store",
6470
"bind",
6571
"opinionated"
6672
],
6773
"peerDependencies": {
68-
"firebase": "^2.4.1 || >= 3.0.0"
74+
"firebase": ">= 4.0.0"
6975
},
7076
"author": "Eduardo San Martin Morote <[email protected]>",
7177
"license": "MIT",

0 commit comments

Comments
 (0)