BetterDiscordApp-v2/client/src/modules/module.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-01-30 14:20:24 +01:00
/**
* BetterDiscord Module Base
* Copyright (c) 2015-present JsSucks - https://github.com/JsSucks
* All rights reserved.
* https://github.com/JsSucks - https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
2018-01-30 14:20:24 +01:00
*/
/**
* Base Module that every non-static module should extend
*/
2018-01-30 14:20:24 +01:00
export default class Module {
constructor(args) {
this.__ = {
state: args || {},
args
};
2018-01-30 14:20:24 +01:00
this.setState = this.setState.bind(this);
2018-02-01 04:00:28 +01:00
this.initialize();
2018-01-30 14:20:24 +01:00
}
2018-02-01 04:00:28 +01:00
initialize() {
2018-01-30 14:20:24 +01:00
if (this.bindings) this.bindings();
if (this.setInitialState) this.setInitialState(this.state);
if (this.events) this.events();
}
setState(newState) {
const oldState = this.state;
Object.assign(this.state, newState);
if (this.stateChanged) this.stateChanged(oldState, newState);
}
set args(t) { }
get args() { return this.__.args; }
set state(state) { return this.__.state = state; }
get state() { return this.__.state; }
}