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(){
|
created(){
|
||||||
let sockets = this.$options['sockets']
|
let sockets = this.$options['sockets']
|
||||||
|
|
||||||
this.$options.sockets = new Proxy({}, {
|
// define on and off as non-enumerable properties
|
||||||
set: (target, key, value) => {
|
Object.defineProperty(this.$options.sockets, 'on', {
|
||||||
Emitter.addListener(key, value, this)
|
value: (label, callback) => {
|
||||||
target[key] = value
|
Emitter.addListener(label, callback, this);
|
||||||
return true;
|
|
||||||
},
|
|
||||||
deleteProperty: (target, key) => {
|
|
||||||
Emitter.removeListener(key, this.$options.sockets[key], this)
|
|
||||||
delete target.key;
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(this.$options.sockets, 'off', {
|
||||||
|
value: (label, callback) => {
|
||||||
|
Emitter.removeListener(label, callback, this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if(sockets){
|
if(sockets){
|
||||||
Object.keys(sockets).forEach((key) => {
|
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){
|
if(sockets){
|
||||||
Object.keys(sockets).forEach((key) => {
|
Object.keys(sockets).forEach((key) => {
|
||||||
delete this.$options.sockets[key]
|
Emitter.removeListener(key, sockets[key], this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue