nik-zp / Vue-Mqtt

Connect to mqtt through websocket, implementation for Vuejs 2
95 stars 33 forks source link

mqtt proxy is created for all child components #13

Open mazoqui opened 4 years ago

mazoqui commented 4 years ago

At plugin install method, the mixing is creating a Proxy instance for components that does not declare mqtt

Vue.mixin({ created() {
let mqtt = this.$options['mqtt'];
if (mqtt) { this.$options.mqtt = new Proxy({}, { set: (target, key, value) => { Emitter.addListener(key, value, this); target[key] = value; return true; }, deleteProperty: (target, key) => { Emitter.removeListener(key, this.$options.mqtt[key], this); delete target.key; return true; } }); Object.keys(mqtt).forEach((key) => { this.$options.mqtt[key] = mqtt[key]; }); } },` code seems to work without extra instance.