petermichaux / maria

The MVC framework for JavaScript applications. The real MVC. The Smalltalk MVC. The Gang of Four MVC.
BSD 2-Clause "Simplified" License
764 stars 51 forks source link

Optimize maria.SetView.prototype.handleDelete #1

Closed petermichaux closed 11 years ago

petermichaux commented 12 years ago

There is plenty of looping in maria.SetView.prototype.handleDelete. The "j" loop could be removed if a tag property like "_maria_SetView_id" was added to each item model object and then a mapping from these ids to view objects was kept.

maria.SetView.prototype.handleDelete = function(evt) {
    var childModels = evt.relatedTargets;
    for (var i = 0, ilen = childModels.length; i < ilen; i++) {
        var key = childModels[i]._maria_SetListView_id;
        this.removeChild(this._mapping[key]);
        delete this._mapping[key];
    }
};

Need initialize and keep this mapping up-to-date throughout SetView's implementation and ensure it is destroyed correctly.

This is an optimization to consider when SetView proves itself as something useful that will stay around permanently.

Sure could use ES.next Map right about now.

petermichaux commented 11 years ago

Seems to be efficient enough for now.