Skip to content

Instantly share code, notes, and snippets.

Created November 4, 2013 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/cb509cc3ad2ffbae86b6 to your computer and use it in GitHub Desktop.
Save anonymous/cb509cc3ad2ffbae86b6 to your computer and use it in GitHub Desktop.
zoosk.services.shared.SafeApplyFactoryFactory = function($rootScope) {
return function safeApplyFactory(fn, opt_context, var_args) {
var factoryArgs = [].slice.call(arguments, 2);
return function safeApplyWrapper() {
var factoryAndWrapperArgs = factoryArgs.concat([].slice.call(arguments));
var fnCall = typeof(fn) == 'function' ? function() {
return fn.apply(opt_context, factoryAndWrapperArgs);
} : angular.noop;
var phase = $rootScope.$root.$$phase;
if (phase != '$apply' && phase != '$digest') {
return $rootScope.$apply(fnCall);
}
return fnCall();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment