mirror of
https://github.com/MetinSeylan/Vue-Socket.io.git
synced 2025-04-16 15:21:28 +02:00
Change .sockets interface to use 'on' and 'off' methods to avoid using Proxy
This commit is contained in:
parent
22049133d5
commit
50bd360b6a
1 changed files with 13 additions and 13 deletions
26
src/Main.js
26
src/Main.js
|
@ -15,22 +15,22 @@ export default {
|
|||
created(){
|
||||
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
|
||||
// define on and off as non-enumerable properties
|
||||
Object.defineProperty(this.$options.sockets, 'on', {
|
||||
value: (label, callback) => {
|
||||
Emitter.addListener(label, callback, this);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Object.defineProperty(this.$options.sockets, 'off', {
|
||||
value: (label, callback) => {
|
||||
Emitter.removeListener(label, callback, this);
|
||||
}
|
||||
});
|
||||
|
||||
if(sockets){
|
||||
Object.keys(sockets).forEach((key) => {
|
||||
this.$options.sockets[key] = sockets[key];
|
||||
Emitter.addListener(key, sockets[key], this);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -39,7 +39,7 @@ export default {
|
|||
|
||||
if(sockets){
|
||||
Object.keys(sockets).forEach((key) => {
|
||||
delete this.$options.sockets[key]
|
||||
Emitter.removeListener(key, sockets[key], this);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue