2
0
mirror of https://github.com/tenrok/vue-native-websocket.git synced 2026-06-14 21:22:28 +03:00
This commit is contained in:
metinseylan
2016-12-31 01:18:10 +03:00
parent c7491fc762
commit 8e0100be09
8 changed files with 143 additions and 86 deletions
Regular → Executable
+22 -10
View File
@@ -3,33 +3,43 @@ import Emitter from './Emitter'
export default {
install(Vue, connection){
install(Vue, connection, store){
if(!connection) throw new Error("[Vue-Socket.io] cannot locate connection")
let observer = new Observer(connection)
let observer = new Observer(connection, store)
Vue.prototype.$socket = observer.Socket;
Vue.mixin({
beforeCreate(){
let _this = this;
let sockets = this.$options['sockets']
this.$options.sockets = new Proxy({}, {
set: (target, key, value) => {
Emitter.addListener(key, value, this)
target[key] = value
return true;
},
deleteProperty: (target, key) => {
Emitter.removeListener(key, this.$options.sockets[key], this)
delete target.key;
return true
}
})
if(sockets){
Object.keys(sockets).forEach(function(key) {
Emitter.addListener(key, sockets[key], _this)
Object.keys(sockets).forEach((key) => {
this.$options.sockets[key] = sockets[key];
});
}
},
beforeDestroy(){
let _this = this;
let sockets = this.$options['sockets']
if(sockets){
Object.keys(sockets).forEach(function(key) {
Emitter.removeListener(key, sockets[key], _this)
Object.keys(sockets).forEach((key) => {
delete this.$options.sockets[key]
});
}
}
@@ -37,4 +47,6 @@ export default {
}
}
}