-
Notifications
You must be signed in to change notification settings - Fork 39
Consider using ResizeObserver #618
Comments
I hava a Container widget which contains widget A and widget B。 <widget> Container
<widget>A</widget>
<widget>B</widget>
</widget>
<widget>C</widget>
<widget>D</widget> So I use use resize-observer-polyfill to observe the selected widget's position and size change. In Container widget's protected onElementCreated(element: Element, key: string | number) {
const { onFocusChanged } = this.properties;
this._resizeObserver = new ResizeObserver((entries, observer) => {
for (const entry of entries) {
const focusDimensions = getEnclosingWidgetDimensions(entry.target);
onFocusChanged &&
onFocusChanged({
focusDimensions
});
}
});
this._resizeObserver.observe(element);
} then, and a private _onMouseUp(event: MouseEvent) {
const selectedElement = this.getEnclosingWidget(event.target);
if (this._focusDom != null) {
this._resizeObserver.unobserve(this._focusDom);
}
this._focusDom = selectedElement ;
this._resizeObserver.observe(this._focusDom);
}
protected render() {
return v('div', {'onmouseup': this._onMouseUp}, [....]);
} But I found |
Enhancement/Discussion
We might want to consider using a
ResizeObserver
polyfill to allow theDimensions
meta manager to perform better, allowing it to detect changes to DOM elements that change the size information of a DOM element.The draft spec is available at WICG ResizeObserver Draft. A well thought out polyfill is available at que-etc/resize-observer-polyfill which uses MutationObservers and Mutation Events to provide spec compliant functionality with some minor limitations.
It is currently available natively in Chrome/Opera under a flag.
Right now, every time a widget is re-rendered, any nodes that are registered with the Dimensions meta manager will have their bounding rectangle re-calculated, whether it has actually been changed. This would allow the manager to be more reactive and keep a cache of size information, of which its observed DOM elements would have their values updated on actual resize.
Because the polyfill is designed to deliver the resize changes only when it is convinced it has the right information, there could be an issue where the queuing of changes get delivered after the DOM has be re-rendered after an invalidation, either causing a double invalidation or incorrect information being offered up to the widgets. This would require investigation to help ensure that it operates effectively.
The text was updated successfully, but these errors were encountered: