Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add infObserveResize directive #60

Closed
wants to merge 3 commits into from
Closed

Add infObserveResize directive #60

wants to merge 3 commits into from

Conversation

Erbenos
Copy link
Contributor

@Erbenos Erbenos commented Mar 1, 2022

Description

Abstracts ResizeObserver into primitive directive.

Tests simple interaction that replaces underlying ResizeObserver with mocks as Jest does not support ResizeObserver and testing a polyfill would negate the point of it anyway.

Documentation includes notes on how to test events fired from the directive if need be.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (Jest doesn't support ResizeObserver)
  • New and existing unit tests pass locally with my changes

@Erbenos Erbenos requested a review from fvoska as a code owner March 1, 2022 18:54
@nx-cloud
Copy link

nx-cloud bot commented Mar 1, 2022

Nx Cloud Report

CI is running for commit 90d0b12.

📂 Click to track the progress, see the status, the terminal output, and the build insights.


Sent with 💌 from NxCloud.

@Erbenos
Copy link
Contributor Author

Erbenos commented Mar 4, 2022

TODO myself: add directive to exports

});
```

Unfortunately above won't as well as when we run the tests, we will see it complaining that expected `heightOutputDebugEl` innerText doesn't match `newHeight`. Why is that?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you maybe missing a word in this sentence ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Unfortunately above won't as well as when we run the tests, we will see it complaining that expected `heightOutputDebugEl` innerText doesn't match `newHeight`. Why is that?

Clearly the browser doesn't fire ResizeObserver notifications the instant one of the elements gets resized or to make it clearer, it doesn't trigger the moment anything which could cause a resize happens. Instead, it runs as described in [spec](https://www.w3.org/TR/resize-observer/#html-event-loop), TL;DR after layout gets updated, but before repaint. Closest the end of that would be using `requestAnimationFrame` with `setTimeout`, where `requestAnimationFrame` runs its callback just before the repaint happens, we can defer it to next macrotask with `setTimeout` (which is bound to happen after repaint). We could use artificial delay as well, but that wouldn't guarantee the execution after the next repaint.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR sentence isn't clear to me as well, Should it maybe be smth like "after layout gets updated, but before repaint ResizeObserver notification is fired?

Copy link
Contributor Author

@Erbenos Erbenos Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to reword the paragraph a little bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template: `
<h2>Content rect:</h2>
<pre>{{ measurements$ | async | json }}</pre>
<button (click)="appendText()">Append text</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

click handler naming -> onAppendTextClick(),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<h2>Content rect:</h2>
<pre>{{ measurements$ | async | json }}</pre>
<button (click)="appendText()">Append text</button>
<button (click)="toggleContent()">Toggle content</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

click handler naming -> onToggleContentClick(),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Erbenos
Copy link
Contributor Author

Erbenos commented Mar 24, 2022

Thanks for review so far.

@Erbenos Erbenos requested a review from JosipJanus May 19, 2022 16:52
@fvoska
Copy link
Contributor

fvoska commented Jan 17, 2024

Abandoning in favour of https://taiga-family.github.io/ng-web-apis/resize-observer

@fvoska fvoska closed this Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants