Files
standardnotes-app-web/app/assets/javascripts/controllers/abstract/pure_ctrl.js
2020-02-04 14:20:20 +01:00

28 lines
601 B
JavaScript

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));
}
}