Refactors most controllers and directives into classes for more organized and maintainable code
This commit is contained in:
28
app/assets/javascripts/controllers/abstract/pure_ctrl.js
Normal file
28
app/assets/javascripts/controllers/abstract/pure_ctrl.js
Normal file
@@ -0,0 +1,28 @@
|
||||
export class PureCtrl {
|
||||
constructor(
|
||||
$timeout
|
||||
) {
|
||||
if(!$timeout) {
|
||||
throw 'Invalid PureCtrl construction.';
|
||||
}
|
||||
this.$timeout = $timeout;
|
||||
this.state = {};
|
||||
this.props = {};
|
||||
}
|
||||
|
||||
async setState(state) {
|
||||
return new Promise((resolve) => {
|
||||
this.$timeout(() => {
|
||||
this.state = Object.freeze(Object.assign({}, this.state, state));
|
||||
resolve();
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
initProps(props) {
|
||||
if (Object.keys(this.props).length > 0) {
|
||||
throw 'Already init-ed props.';
|
||||
}
|
||||
this.props = Object.freeze(Object.assign({}, this.props, props));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user