vue-plugin-helper-decorator
Version:
A bundle of decorator for using vue plugin
28 lines • 970 B
JavaScript
import { createDecorator } from 'vue-class-component';
/**
* Vue-Socket.io helper
* Adding the method in the component sockets options
* https://github.com/MetinSeylan/Vue-Socket.io
*/
export function SocketIO(socketOption) {
return createDecorator(function (componentOptions, handler) {
const options = componentOptions;
if (typeof options.sockets !== 'object') {
options.sockets = Object.create(null);
}
if (socketOption && socketOption.name) {
if (Array.isArray(socketOption.name)) {
socketOption.name.forEach(name => {
options.sockets[name] = options.methods[handler];
});
}
else {
options.sockets[socketOption.name] = options.methods[handler];
}
}
else {
options.sockets[handler] = options.methods[handler];
}
});
}
//# sourceMappingURL=vue-socket.io.js.map