lega911 / angular-light

Alight is a library for building interactive MVVM web interfaces/applications. (project is deprecated)
MIT License
274 stars 43 forks source link

Manual filter update #238

Closed Ni55aN closed 7 years ago

Ni55aN commented 7 years ago

This filter does not update data

alight.filters.filterInputControl = function (input) {
    return input.filter(function (item) {
        return item.showControl();
    });
}

The next one updates, but with the "deep", which for large objects effects the performance


alight.filters.filterInputControl = ffunction(){}
alight.filters.filterInputControl.prototype.onChange = function(value) {
    value = value.filter(function (item) {
        return item.showControl();
    })
    this.setValue(value);
}
alight.filters.filterInputControl.prototype.watchMode = 'deep'; <----

Is there any ways to update data correctly without deep watching? Mayby some manual methods?

Ni55aN commented 7 years ago

simple example http://jsfiddle.net/ktpoofcp/5/

lega911 commented 7 years ago

Filter "doesn't work" because list isn't changed, only object in it, and it isn't watched by default. As option you can use a function instead of filter: http://jsfiddle.net/lega911/nfp52ccr/ it works faster than 'deep' Or you can replace item of list: http://jsfiddle.net/lega911/Lqq96sn7/