-
Notifications
You must be signed in to change notification settings - Fork 0
/
mixin.js
51 lines (38 loc) · 1.13 KB
/
mixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Mixin dependencies
*/
var noop = require('101/noop');
var Fire = require('./lib/fire');
/**
* The vue-fire mixin
*
* @param app {String} The Firebase application name
*/
module.exports = function (app) {
var root = new Firebase('https://' + app + '.firebaseio.com');
return {
created: function () {
var vm = this;
var firebase = this.$options.firebase || noop;
var refs = firebase.call(vm, root) || {};
var arrays = refs.arrays || [];
var values = refs.values || [];
vm.$firebase = new Fire(vm, root);
values.forEach(function (keyPath) {
vm.$firebase.setValue(keyPath)
});
arrays.forEach(function (ref) {
var setter = function() { return ref };
vm.$firebase.setArray(setter);
});
},
attached: function () {
console.log('attached');
this.$firebase.attachListeners();
},
detached: function () {
console.log('detached');
this.$firebase.detachListeners();
}
}
};