daniel-nagy / fixed-table-header

Fixed table header directive.
MIT License
88 stars 36 forks source link

Reduce watcher by using ResizeObserver #43

Open antsfiles opened 5 years ago

antsfiles commented 5 years ago

I found out that 'getWitht' is CPU consuming if there is a lot of $digest. So instead of using $watch, ResizeObserver in chrome is a better choice.

                    if (ResizeObserver) {
                        //window.console.log("ResizeObserver exists", ResizeObserver);
                        new ResizeObserver((outputsize) => {
                            getWidth();
                            setWidth();
                        }).observe(cell[0]);
                    } else {
                        //window.console.log("ResizeObserver does not exists", ResizeObserver);
                        var listener = scope.$watch(getWidth, setWidth);
                    }

Also, "scope.$watch(cells, updateCells);" is not need, I think, if the number of cells in header does not change. It can be replace directly by "updateCells();"