Skip to content

Instantly share code, notes, and snippets.

@thomasdunn
Created March 20, 2015 09:04
Show Gist options
  • Save thomasdunn/829f4e36bbcc4fc4a1b7 to your computer and use it in GitHub Desktop.
Save thomasdunn/829f4e36bbcc4fc4a1b7 to your computer and use it in GitHub Desktop.
'use strict';
/*jshint esnext: true */
class ToolsService {
constructor($rootScope) {
this.rootScope = $rootScope;
this.brushRadius = 1;
this.brushRadiusSetMessage = 'brushRadiusSetMessage';
}
set brushRadius(radius) {
this.rootScope.$broadcast(this.brushRadiusSetMessage, radius);
}
onBrushRadiusSet($scope, handler) {
$scope.$on(this.brushRadiusSetMessage, function(event, radius) {
handler(radius);
});
}
}
ToolsService.$inject = ['$rootScope'];
export default ToolsService;
'use strict';
/*jshint esnext: true */
class MainController {
constructor ($scope, $window, $document, toolsService) {
this.radius = 10;
toolsService.onBrushRadiusSet($scope, r => this.radius = r);
}
}
@thomasdunn
Copy link
Author

PubSub events in Angular 1.x with ES6. Modeled after: http://eburley.github.io/2013/01/31/angularjs-watch-pub-sub-best-practices.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment