'use strict';

var compareByDepth = require('./compare-by-depth.js');
var array = require('../../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/array.js');

class FlatTree {
    constructor() {
        this.children = [];
        this.isDirty = false;
    }
    add(child) {
        array.addUniqueItem(this.children, child);
        this.isDirty = true;
    }
    remove(child) {
        array.removeItem(this.children, child);
        this.isDirty = true;
    }
    forEach(callback) {
        this.isDirty && this.children.sort(compareByDepth.compareByDepth);
        this.isDirty = false;
        this.children.forEach(callback);
    }
}

exports.FlatTree = FlatTree;
