Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Consider using ResizeObserver #618

Closed
kitsonk opened this issue Jul 25, 2017 · 1 comment
Closed

Consider using ResizeObserver #618

kitsonk opened this issue Jul 25, 2017 · 1 comment
Milestone

Comments

@kitsonk
Copy link
Member

kitsonk commented Jul 25, 2017

Enhancement/Discussion

We might want to consider using a ResizeObserver polyfill to allow the Dimensions 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.

@kitsonk kitsonk added this to the 2017.08 milestone Jul 28, 2017
@kitsonk kitsonk modified the milestones: 2017.08, 2017.09 Sep 4, 2017
@dylans dylans modified the milestones: 2017.09, 2017.10 Oct 10, 2017
@kitsonk kitsonk removed the beta3 label Oct 30, 2017
@kitsonk kitsonk removed this from the 2017.10 milestone Oct 30, 2017
@kitsonk kitsonk added rc and removed discussion labels Oct 30, 2017
@kitsonk kitsonk added this to the rc.1 milestone Oct 30, 2017
@bitpshr bitpshr mentioned this issue Nov 30, 2017
3 tasks
@matt-gadd matt-gadd removed the blocker label Dec 22, 2017
@agubler agubler removed the rc label Jan 4, 2018
@agubler agubler removed this from the rc.1 milestone Jan 4, 2018
@xiaohulu
Copy link

I hava a Container widget which contains widget A and widget B
When use mouse to select Container, A or B, then widget C and widget D change position
depend on the selected widget's position(left and bottom)

<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 onElementCreate, I create a private ResizeObserver, for example:

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 mouseup event for Container widget, here I do not want to create a mouseup event for each child widget(for example C and D), I want to use a delegate event at Container widget, because may has many children widgets.

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 onElementCreate was removed. How to Implement this feature without onElementCreate, custom a ResizeObserver Meta? But how to support delegate event?

@tomdye tomdye mentioned this issue Apr 3, 2018
3 tasks
@dylans dylans added this to the 2.0.0 milestone Apr 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants