vue-fiery
Vue.js binding for Google Firebase Cloud Firestore.
Features
- Documents example
- Collections (stored as array or map) example
- Queries (stored as array or map) example
- Real-time or once example
- Data or computed properties example
- Adding, updating, sync, removing, remove field example
- Sub-collections (with cascading deletions!) example
- Return instances of a class example
- Add active record methods (sync, update, remove, clear, getChanges) example
- Control over what properties are sent on save example
- Encode & decode properties example
- Adding the key to the document example
- Callbacks (error, success, missing, remove) example
- Custom binding / unbinding
Contents
Dependencies
- Firebase ^5.0.0
- Vue: ^1.0.28
Installation
npm
Installation via npm : npm install vue-fiery --save
Usage
Vue const firebaseApp = firebaseconst db = firebaseApp; var vm = el: '#app' { return todos: this // live collection, ford: this // live document role: 'admin' } computed: // Updated when role changes { return this }
Each record of the array will contain a .uid
property. This helps identify
what firestore database the document is stored, in what collection, and with which options
Documents
const db = firebaseApp; inject: 'currentUserId' { const $fiery = this$fiery return settings: currentUser: // not reactive, but is updated real-time }
Collections
const db = firebaseApp; { const $fiery = this$fiery return cars: // real-time array carMap: // real-time map: carMap[id] = car }
Queries
const db = firebaseApp; inject: 'currentUserId' { const $fiery = this$fiery return currentCars: currentCarMap: }
Real-time or once
const db = firebaseApp; inject: 'currentUserId' { const $fiery = this$fiery return // real-time is default, all you need to do is specify once: true to disable it cars: // array populated once currentUser: // current user populated once }
Data or computed
const db = firebaseApp; inject: 'currentUserId' { // data examples above return limit: 25 status: 'unfinished' } computed: { return this // reactive and real-time } { return this }
Adding, updating, overwriting, removing
const db = firebaseApp; inject: 'currentUserId' { return todos: this } computed: { return this } methods: { // COLLECTIONS STORED IN $fires // once successful, this.todos will be updated this$firestodos } { this$fiery } { this$fiery } { // any document can be passed, ex: this.todos[1], this.currentUser this$fiery } { // only fields present on data will exist on sync this$fiery } { this$fiery // removes sub collections as well this$fiery // preserves sub collections } { this$fierycleardata 'name' // can also specify an array of props or sub collections }
Sub-collections
You can pass the same options to sub, nesting as deep as you want!
const db = firebaseApp; { return // this.todos[todoIndex].children[childIndex] todos: this } methods: { // or this.$fiery.ref(parent, 'children') for short this$fiery } { this$fieryclearparent 'children' // clear the sub collection }
Return instances of a class
{ }Todoprototype = { thisdone = true thisupdated_at = Date thisupdated_by = byUserid } const db = firebaseApp; { return // this.todos[todoIndex] instanceof Todo todos: this }
Active Record
// can be used with type, doesn't have to be { }Todoprototype = { thisdone = true thisupdated_at = Date thisupdated_by = byUserid this } const db = firebaseApp; { return todos: this todosCustom: this } methods: { // instead of this.$fiery.update(this.todos[index]) thistodosindex } { // instead of this.$fiery.update(this.todosCustom[index]) thistodosCustomindex } { todo // assuming currentUser exists } { todo }
Save fields
const db = firebaseApp; { return todos: this } methods: { this$fiery } { this$fiery // only send this value if it exists } { this$fiery // ignores exclude and include when specified }
Encode & decode properties
const db = firebaseApp; { return todos: this }
Adding key to object
const db = firebaseApp; { return todos: this // must be excluded manually } methods: { // todo.id exists now console }
Callbacks
const db = firebaseApp; { return todos: this }