Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
60 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import camelCase from "lodash/camelCase"; | ||
|
||
const requireModule = require.context('.', false, /\.js$/); | ||
const modules = {}; | ||
|
||
requireModule.keys().forEach(filename => { | ||
if(filename !== './index.js') { | ||
const moduleName = camelCase(filename.replace(/(\.\/|\.js)/g, '')); | ||
modules[moduleName] = requireModule(filename).default; | ||
} | ||
}); | ||
// console.log(Object.keys(modules)); | ||
|
||
export default modules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function getMixin(vm) { | ||
const {socket} = vm.$options; | ||
if(socket) { | ||
return typeof socket === 'function' ? socket.call(vm) : socket; | ||
} | ||
} | ||
|
||
const serverMixin = null; | ||
|
||
const clientMixin = { | ||
data() { | ||
return { | ||
socketEvents : [], | ||
} | ||
}, | ||
mounted() { | ||
const socket = getMixin(this); | ||
if(socket) { | ||
this.socketEvents = Object.keys(socket); | ||
for(const ev of this.socketEvents) { | ||
this.$socket.on(ev, socket[ev]) | ||
} | ||
} | ||
}, | ||
destroyed() { | ||
for(const ev of this.socketEvents) { | ||
this.$socket.off(ev) | ||
} | ||
} | ||
} | ||
|
||
export default process.env.VUE_ENV === 'server' ? serverMixin : clientMixin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters