Skip to content

Enabled firebase to be called as function, thus enabling patterns where Firebase ref's are stored in root component #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 9, 2016
1 change: 1 addition & 0 deletions dist/vuefire.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ return /******/ (function(modules) { // webpackBootstrap
var init = function () {
var bindings = this.$options.firebase
if (!bindings) return
if (typeof bindings === 'function') bindings = bindings.call(this)
ensureRefs(this)
for (var key in bindings) {
bind(this, key, bindings[key])
Expand Down
2 changes: 1 addition & 1 deletion dist/vuefire.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/vuefire.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ function ensureRefs (vm) {
}

var init = function () {
if (!this.$options.firebase) return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't clear about this, sorry. I was thinking about this:

var bindings = this.$options.firebase
if (typeof bindings === 'function') bindings = bindings.call(this)
if (!bindings) return

var bindings = this.$options.firebase
if (!bindings) return
if (typeof bindings === 'function') bindings = bindings.call(this)
ensureRefs(this)
for (var key in bindings) {
bind(this, key, bindings[key])
Expand Down
13 changes: 13 additions & 0 deletions tests/vuefire.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ describe('VueFire', function () {
})
})

describe('support Function options', function () {
it('option is callable as function', function (done) {
var spy = sinon.spy()
expect(function () {
new Vue({
firebase: spy
}).$mount()
}).to.not.throw()
expect(spy.calledOnce).to.be.true
done()
})
})

describe('bind as Array', function () {
it('throws error for invalid firebase ref', function () {
helpers.invalidFirebaseRefs.forEach(function (ref) {
Expand Down