Global is a module

This commit is contained in:
Jiiks 2018-01-12 21:46:55 +02:00
parent 7be0ab71fc
commit e1932b7f74
2 changed files with 34 additions and 5 deletions

View File

@ -8,15 +8,21 @@
* LICENSE file in the root directory of this source tree.
*/
class Global {
const { Module } = require('./basemodule');
constructor() {
class Global extends Module {
bindings() {
this.first = this.first.bind(this);
this.setWS = this.setWS.bind(this);
}
first() {
if (window.__bd) {
this.__globals = window.__bd;
this.setState({
globals: window.__bd
});
window.__bd = {
setWS: this.setWS
}
@ -24,7 +30,9 @@ class Global {
}
setWS(wSocket) {
this.__globals.wsHook = wSocket;
const { globals } = this.state;
globals.wSocket = wSocket;
this.setState({globals});
}
}

View File

@ -36,8 +36,29 @@ class Module {
set args(t) { }
get args() { return this.__.args; }
set state(state) { return this.__.state = state; }
get state() { return this.__.state; }
}
module.exports = { Module };
module.exports = { Module };
class Foo2 {
constructor() {
this.__ = {
state: {'lo': 'hi'}
}
}
set state(state) {
return this.__.state = state;
}
get state() {
return this.__.state;
}
}