Code coverage report for ./src/DependencyTree.js

Statements: 92.59% (25 / 27)      Branches: 78.57% (11 / 14)      Functions: 85.71% (6 / 7)      Lines: 92.59% (25 / 27)      Ignored: none     

All files » ./src\ » DependencyTree.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47      2 2   2 1368 1368 1368     2 876 876 876     2 1532 1532 656 656 656 2     654     876     2 876 876       876 876     2      
/**
 * Created by exodia on 14-5-21.
 */
void function (define) {
    define(
        function () {
            var DependencyNode = function () {
                this.data = [];
                this.children = [];
                this.parent = null;
            };
 
            DependencyNode.prototype.appendChild = function (node) {
                node.parent = this;
                this.children.push(node);
                return node;
            };
 
            DependencyNode.prototype.checkForCircular = function (id) {
                var node = this.parent;
                if (node !== null) {
                    var data = node.data;
                    for (var i = data.length - 1; i > -1; --i) {
                        if (node.data[i].id && node.data[i].id === id) {
                            return node.data[i];
                        }
 
                        return node.checkForCircular(id);
                    }
                }
                return null;
            };
 
            DependencyNode.prototype.addData = function (data, checkForCircular) {
                checkForCircular = !!checkForCircular;
                Iif (checkForCircular && this.checkForCircular(data.id)) {
                    return false;
                }
 
                this.data.push(data);
                return true;
            };
 
            return DependencyNode;
        });
 
}(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory; });