angular.module('codebrag.commits')

    .factory('commitsService', function(allCommitsListService, pendingCommitsListService) {

        var toReviewService = true;

        var proxyService = {};


        proxyService.setToReviewMode = function() {
            toReviewService = true;
        };

        proxyService.setAllMode = function() {
            toReviewService = false;
        };

        setupDelegatesOn(proxyService);

        function setupDelegatesOn(dest) {
            var functionsToDelegate = _.union(findFunctionsToDelegate(pendingCommitsListService), findFunctionsToDelegate(allCommitsListService));
            functionsToDelegate.forEach(function(delegate) {
                dest[delegate] = function() {
                    var target = getCurrentImpl();
                    return target[delegate].apply(target, arguments);
                }
            });
        }

        function findFunctionsToDelegate(srcObj) {
            var functions = [];
            for (var p in srcObj) {
                if (srcObj.hasOwnProperty(p) && _.isFunction(srcObj[p])) {
                    functions.push(p);
                }
            }
            return functions;
        }

        function getCurrentImpl() {
            return toReviewService ? pendingCommitsListService : allCommitsListService
        }

        return proxyService;

    });
@@ -28,16 +28,316 @@
 mmits')%0A
+    /**%0A     * It's kind of delegate that has two possible implemenations for all and pending commits%0A     * Depending on what caller needs (with prior calls to setAllMode or setToReviewMode)%0A     * suitable implementation is called.%0A     *%0A     * Most of the code here is to create delegates%0A     */
 %0A    .fa

Add comment to commitsService that this is only proxy to other implementations.