WIP
This commit is contained in:
@@ -1,13 +1,25 @@
|
||||
export class PureCtrl {
|
||||
constructor(
|
||||
$timeout
|
||||
$scope,
|
||||
$timeout,
|
||||
application,
|
||||
appState
|
||||
) {
|
||||
if(!$timeout) {
|
||||
if (!$scope || !$timeout || !application || !appState) {
|
||||
throw 'Invalid PureCtrl construction.';
|
||||
}
|
||||
this.$scope = $scope;
|
||||
this.$timeout = $timeout;
|
||||
this.appState = appState;
|
||||
this.application = application;
|
||||
this.state = {};
|
||||
this.props = {};
|
||||
this.addAppStateObserver();
|
||||
this.addAppEventObserver();
|
||||
$scope.$on('$destroy', () => {
|
||||
this.unsubApp();
|
||||
this.unsubState();
|
||||
});
|
||||
}
|
||||
|
||||
async setState(state) {
|
||||
@@ -25,4 +37,25 @@ export class PureCtrl {
|
||||
}
|
||||
this.props = Object.freeze(Object.assign({}, this.props, props));
|
||||
}
|
||||
|
||||
addAppStateObserver() {
|
||||
this.unsubState = this.appState.addObserver((eventName, data) => {
|
||||
this.onAppStateEvent(eventName, data);
|
||||
});
|
||||
}
|
||||
|
||||
addAppEventObserver() {
|
||||
this.unsubApp = this.application.addEventObserver((eventName) => {
|
||||
this.onApplicationEvent(eventName);
|
||||
});
|
||||
}
|
||||
|
||||
onApplicationEvent(eventName) {
|
||||
/** Optional override */
|
||||
}
|
||||
|
||||
onAppStateEvent(eventName, data) {
|
||||
/** Optional override */
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user