Skip to content

Commit

Permalink
feat(refs): add $firestoreRefs
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Nov 17, 2017
1 parent e6716e1 commit d7a90ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function install (Vue, options) {
created () {
const { firestore } = this.$options
this._firestoreUnbinds = Object.create(null)
this.$firestoreRefs = Object.create(null)
if (!firestore) return
Object.keys(firestore).forEach(key => {
this.$bind(key, firestore[key])
Expand All @@ -110,6 +111,7 @@ function install (Vue, options) {
key,
ref,
})
this.$firestoreRefs[key] = ref
}

Vue.prototype.$unbind = function (key) {
Expand Down
7 changes: 7 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ test('setups _firestoreUnbinds with no firestore options', t => {
t.truthy(vm._firestoreUnbinds)
t.deepEqual(Object.keys(vm._firestoreUnbinds), [])
})

test('setups _firestoreRefs', t => {
const vm = t.context.vm
t.deepEqual(Object.keys(vm.$firestoreRefs).sort(), ['item', 'items'])
t.is(vm.$firestoreRefs.item, t.context.document)
t.is(vm.$firestoreRefs.items, t.context.collection)
})

0 comments on commit d7a90ee

Please sign in to comment.