Created
March 20, 2015 09:04
-
-
Save thomasdunn/829f4e36bbcc4fc4a1b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/*jshint esnext: true */ | |
class MainController { | |
constructor ($scope, $window, $document, toolsService) { | |
this.radius = 10; | |
toolsService.onBrushRadiusSet($scope, r => this.radius = r); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PubSub events in Angular 1.x with ES6. Modeled after: http://eburley.github.io/2013/01/31/angularjs-watch-pub-sub-best-practices.html