code: function applied(fn, scope) {
      if (fn.wrappedInApply) {
        return fn;
      }
      var wrapped = function() {
        var args = arguments;
        var phase = scope.$root.$$phase;
        if (phase === "$apply" || phase === "$digest") {
          return fn.apply(null, args);
        } else {
          return scope.$apply(function() {
            return fn.apply( null, args );
          });
        }
      };
      wrapped.wrappedInApply = true;
      return wrapped;
    }
docs: wraps a function with scope.$apply, if already applied just return