Last active
December 25, 2015 09:29
-
-
Save PatrickJS/6954106 to your computer and use it in GitHub Desktop.
Angular Module Pattern
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
| !function(app) { | |
| 'use strict'; | |
| app.factory('Tracking', function($rootScope, $log) { | |
| var _tracking = {}; | |
| _tracking.success = function(event, args) { | |
| args = getArgs(arguments); | |
| return function() { | |
| $log.info(event+':success', args); | |
| $rootScope.$broadcast(event+':success', args) | |
| }; | |
| }; | |
| _tracking.error = function(event, args) { | |
| args = getArgs(arguments); | |
| return function() { | |
| $log.info(event+':error', args); | |
| $rootScope.$broadcast(event+':error', args) | |
| }; | |
| } | |
| return _tracking | |
| }); | |
| // Helper functions | |
| function getArgs(args) { | |
| return Array.prototype.slice.call(args, 1); | |
| } | |
| }(angular.module('services')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment