Skip to content

Instantly share code, notes, and snippets.

@justinobney
Created August 14, 2017 13:13
Show Gist options
  • Save justinobney/2a79bd5ecf499d2ff8aa70fd9185f246 to your computer and use it in GitHub Desktop.
Save justinobney/2a79bd5ecf499d2ff8aa70fd9185f246 to your computer and use it in GitHub Desktop.
class AngularComponent {
static $inject = [];
constructor(...args) {
this.$inject = this.constructor.$inject.reduce(
(acc, injectName, index) => ({
...acc,
[injectName]: args[index],
}),
{}
);
}
}
class Controller extends AngularComponent {
static $inject = ['$scope', 'eventBus', 'uiState'];
constructor(...args) {
super(...args);
// if you need other things here...
// if not, remove constructor...
}
$onInit() {
this.$inject.eventBus.register(
BROADCAST_EVENTS.CONNECTION_CHANGED,
this._onConnectionChange,
this.$inject.$scope
);
this.$inject.eventBus.register(
BROADCAST_EVENTS.SELECTED_TAKEOFF_UPDATED,
() => this._onConnectionChange(null, true),
this.$inject.$scope
);
}
_onConnectionChange = (e, connected) => {
this.$inject.uiState.syncConnecting = !connected;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment