-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvue-feathers.js
56 lines (46 loc) · 1.62 KB
/
vue-feathers.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
52
53
54
55
56
(function() {
'use strict'
var plugin = {
install: function(Vue, server) {
// Every component will have this
Vue.mixin({
created: function() {
this.$feathers = server
// Setting up the services
this.$services = server.services
if(!this.$options.feathers)
return
// Setting up the events
var keys = Object.keys(this.$options.feathers) // services, IE9+
for(var i = 0; i < keys.length; i++) {
var service = this.$options.feathers[keys[i]]
var ekeys = Object.keys(service) // handlers
for(var k = 0; k < ekeys.length; k++) {
server.service(keys[i]).on(ekeys[k], service[ekeys[k]].bind(this))
}
}
},
beforeDestroy: function() {
// Removing the events
if(!this.$options || !this.$options.feathers)
return
var keys = Object.keys(this.$options.feathers) // services, IE9+
for(var i = 0; i < keys.length; i++) {
var service = this.$options.feathers[keys[i]]
var ekeys = Object.keys(service) // handlers
for(var k = 0; k < ekeys.length; k++) {
server.service(keys[i]).removeListener(ekeys[k], service[ekeys[k]].bind(this))
}
}
}
})
}
}
if(typeof exports === 'object' && typeof module === 'object') {
module.exports = plugin
} else if(typeof define === 'function' && define.amd) {
define(function () { return plugin })
} else if (typeof window !== 'undefined') {
window.VueAsyncData = plugin
}
})()