Js bearcat depend list

Object.size = function(obj) {

            var size = 0, key;

            for (key in obj) {

                if (obj.hasOwnProperty(key)) size++;

            }

            return size;

        };

String.prototype.lowFirstLetter = function() {

return this.charAt(0).toLowerCase() + this.slice(1);

};

        var bdList = bearcat.getBeanFactory().getBeanDefinitions();

var initCount = 0;

        var dataMap = {};

        var list = [];

while(initCount < Object.size(bdList)) {

   for (var bdName in bdList) {

                if (!bdList.hasOwnProperty(bdName)) continue;

                if (dataMap[bdName]) continue;

                var definition = bdList[bdName];

                var depends = definition.propsOn;

                if (depends == undefined && depends.length == 0) {

                    dataMap[bdName] = 1;

                    list.push(bdName);

                    initCount++;

                }else {

                    var value = 1;

                    for (var i = 0; i < depends.length; i++) {

var ref = depends[i].ref;

                        if (!dataMap[depends[i].ref]) {

                            value = -1;

                            continue;

                        }

                        value += dataMap[ref];

                    }

                    if (value > 0) {

                        dataMap[bdName] = value;

                        list.push(bdName);

                        initCount++;

                    }

                }

            }

}

        console.log(dataMap);

list.sort(function(a, b){

return dataMap[a] - dataMap[b];

});

var fileList = [];

var idPaths = __bearcatData__.idPaths;

console.log(idPaths);

for (var i = 0; i < list.length; i++) {

fileList[i] = '"' + idPaths[list[i].lowFirstLetter()] + '"';

}

console.log(fileList.join(', '));

猜你喜欢

转载自song020cn.iteye.com/blog/2264353