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

avoid unnecessary recalculations of required height #10

Merged

Conversation

jelhan
Copy link
Owner

@jelhan jelhan commented Mar 7, 2020

Calculating the required height is an expensive operation. Element.getComputedStyles(), Element.scrollHeight and other features used require the browser to recalculate styles and layout. We should make sure that this is only done once per render.

Such an resize could be triggered by both the input event and a changed argument in the same render. Actually that's very likely as could be seen by this template:

<textarea
  value={{this.val}}
  {{autoresize this.val}}
  {{on "input" (action (mut this.val) value="target.value")}}
/>

This requires to track if resize has been scheduled even if arguments are changed. This is something which is not good supported by functional modifiers. Therefore the implementation is refactored to use class modifiers instead as part of this change.

Closes #8

Calculating the required height is an expensive operation.
`Element.getComputedStyles()`, `Element.scrollHeight` and other features
used require the browser to recalculate styles and layout. We should make
sure that this is only done once per render.

Such an resize could be triggered by both the input event and a changed
argument in the same render. Actually that's very likely as could be seen
by this template:

  <textarea
    value={{this.val}}
    {{autoresize this.val}}
    {{on "input" (action (mut this.val) value="target.value")}}
  />

This requires to track if resize has been scheduled even if arguments are
changed. This is something which is not good supported by functional
modifiers. Therefore the implementation is refactored to use class modifiers
instead as part of this change.
@jelhan jelhan added the enhancement New feature or request label Mar 7, 2020
@jelhan jelhan merged commit de5f748 into master Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

avoid recalculating required element height multiple times per render
1 participant