krescruz / angular-materialize

Angularjs directives for Materialize CSS Framework https://github.com/Dogfalo/materialize
MIT License
396 stars 129 forks source link

Directive ngModel inside ui.materialize.ngModel module may affect the performance of whole application #216

Open sampathLiyanage opened 7 years ago

sampathLiyanage commented 7 years ago

In my app I used this library. When I profiled with chrome devtools, it showed 30% of the cpu time was taken by the code given below.

$timeout(function() {
    // To stop an infinite feedback-loop with material multiple-select.
    if (value instanceof Array && oldValue instanceof Array) {
        if (value.length == oldValue.length) {
            return;
        }
    }
    if (element.is('select')) {
        return;
    }
    // This fix is mainly to get placeholders to appear correctly, and it apparently screws things for the selects, so only doing this on something that isn't a select.
    if (value) {
        element.trigger("change");
    } else if (element.attr('placeholder') === undefined) {
        if (!element.is(":focus"))
            element.trigger("blur");
    }
});    

Apparently this has been added to fix a bug in multiple-select. Better if we find another approach as this affects the performance.

webbiesdk commented 7 years ago

I agree, it is kind of an ugly fix. But the functionality is needed, so any change must preserve the current functionality. Pull requests are welcome.