-
Notifications
You must be signed in to change notification settings - Fork 6
Update to new modifier apis (modify) instead of lifecycles #57
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
Open
betocantu93
wants to merge
3
commits into
lolmaus:gen-4
Choose a base branch
from
betocantu93:update-to-new-apis
base: gen-4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,9 @@ import { | |
| Sizes, | ||
| SIZES_DEFAULT, | ||
| SIZES_HEIGHT_DEFAULT, | ||
| Args, | ||
| } from 'ember-element-query'; | ||
| import { registerDestructor } from '@ember/destroyable'; | ||
| import { inject as service } from '@ember/service'; | ||
| export interface SizeObject { | ||
| name: string; | ||
|
|
@@ -41,9 +43,11 @@ export default class ElementQueryModifier extends Modifier<ModifierArgs> { | |
| sizesHeightDefault: Sizes = SIZES_HEIGHT_DEFAULT; | ||
| sizesRatioDefault: Sizes = SIZES_RATIO_DEFAULT; | ||
|
|
||
| _element?: HTMLElement; // For some reason, this.element is not always available | ||
| _element?: HTMLElement; // For some reason, this._element is not always available | ||
| _firstCall = true; | ||
|
|
||
| named: Args = {}; | ||
|
|
||
| // ------------------- | ||
| // Computed properties | ||
| // ------------------- | ||
|
|
@@ -59,7 +63,7 @@ export default class ElementQueryModifier extends Modifier<ModifierArgs> { | |
| } | ||
|
|
||
| get debounce(): number { | ||
| const { debounce } = this.args.named; | ||
| const { debounce } = this.named; | ||
|
|
||
| return debounce == null ? 100 : debounce; | ||
| } | ||
|
|
@@ -69,7 +73,7 @@ export default class ElementQueryModifier extends Modifier<ModifierArgs> { | |
| } | ||
|
|
||
| get sizes(): Sizes | undefined { | ||
| const { sizes } = this.args.named; | ||
| const { sizes } = this.named; | ||
|
|
||
| // Explicitly opt into default sizes | ||
| if (sizes === true) { | ||
|
|
@@ -93,7 +97,7 @@ export default class ElementQueryModifier extends Modifier<ModifierArgs> { | |
| } | ||
|
|
||
| get sizesHeight(): Sizes | undefined { | ||
| const { sizesHeight } = this.args.named; | ||
| const { sizesHeight } = this.named; | ||
|
|
||
| // Explicitly opt into default sizes | ||
| if (sizesHeight === true) { | ||
|
|
@@ -112,7 +116,7 @@ export default class ElementQueryModifier extends Modifier<ModifierArgs> { | |
| } | ||
|
|
||
| get sizesRatio(): Sizes | undefined { | ||
| const { sizesRatio } = this.args.named; | ||
| const { sizesRatio } = this.named; | ||
|
|
||
| // Explicitly opt into default sizes | ||
| if (sizesRatio === true) { | ||
|
|
@@ -461,7 +465,7 @@ export default class ElementQueryModifier extends Modifier<ModifierArgs> { | |
| size: this.sizeObjectWidthAt?.name, | ||
| sizeHeight: this.sizeObjectHeightAt?.name, | ||
| sizeRatio: this.sizeObjectRatioAt?.name, | ||
| prefix: this.args.named.prefix, | ||
| prefix: this.named.prefix, | ||
| attributes: this.attributes, | ||
| attributesRecord: this.attributesRecord, | ||
| }; | ||
|
|
@@ -472,7 +476,7 @@ export default class ElementQueryModifier extends Modifier<ModifierArgs> { | |
| // ------------------- | ||
|
|
||
| convertSizeToAttribute(size: string, rangeDirection: RangeDirection): string { | ||
| const prefix = this.args.named.prefix ?? ''; | ||
| const prefix = this.named.prefix ?? ''; | ||
|
|
||
| if (typeof prefix !== 'string') { | ||
| throw new Error(`element-query: expected prefix to be a string, was ${typeof prefix}`); | ||
|
|
@@ -497,8 +501,8 @@ export default class ElementQueryModifier extends Modifier<ModifierArgs> { | |
| } | ||
|
|
||
| callOnResize(): void { | ||
| if (this.args.named.onResize) { | ||
| this.args.named.onResize(this.yield); | ||
| if (this.named.onResize) { | ||
| this.named.onResize(this.yield); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -544,7 +548,7 @@ export default class ElementQueryModifier extends Modifier<ModifierArgs> { | |
| } | ||
|
|
||
| _didResizeHandlerSync(): void { | ||
| if (!this.args.named.isDisabled && !this.isDestroying && !this.isDestroyed) { | ||
| if (!this.named.isDisabled && !this.isDestroying && !this.isDestroyed) { | ||
| this.applyAttributesToElement(); | ||
| this.callOnResize(); | ||
| } | ||
|
|
@@ -564,28 +568,26 @@ export default class ElementQueryModifier extends Modifier<ModifierArgs> { | |
| debounceTask(this, '_didResizeHandlerRequestAnimationFrame', this.debounce); | ||
| } | ||
|
|
||
| // ------------------- | ||
| // Lifecycle hooks | ||
| // ------------------- | ||
| didInstall(): void { | ||
| if (!this.element) throw new Error('Expected this.element to be available'); | ||
|
|
||
| this._element = this.element; | ||
|
|
||
| this.resizeObserver.observe(this.element, this.didResizeHandler); // eslint-disable-line @typescript-eslint/unbound-method | ||
|
|
||
| this._didResizeHandlerSync(); // We want to run it as soon as possible to avoid a jump of unstyled content | ||
| } | ||
|
|
||
| didUpdateArguments(): void { | ||
| if (!this.resizeObserver.isEnabled) return; | ||
| modify(element: HTMLElement, _pos: unknown[], named: Args): void { | ||
| this._element = element; | ||
| this.named = named; | ||
| if (this._firstCall) { | ||
| // eslint-disable-next-line @typescript-eslint/unbound-method | ||
| this.resizeObserver.observe(element, this.didResizeHandler); | ||
| this._didResizeHandlerSync(); | ||
|
|
||
| this.didResizeHandler(); | ||
| registerDestructor(this, () => this.cleanup()); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change (arrow function)? In order to remove the lint exception? But we have this exact lint exception used all over the file, so I don't see a point in fixing just one instance. The linter should serve to the developer, not vice versa. :) |
||
| this._firstCall = false; | ||
| } else { | ||
| if (this.resizeObserver.isEnabled) { | ||
| this.didResizeHandler(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| willRemove(): void { | ||
| if (!this.element) throw new Error('Expected this.element to be available'); | ||
| cleanup(): void { | ||
| if (!this._element) throw new Error('Expected this._element to be available'); | ||
|
|
||
| this.resizeObserver.unobserve(this.element, this.didResizeHandler); // eslint-disable-line @typescript-eslint/unbound-method | ||
| this.resizeObserver.unobserve(this._element, this.didResizeHandler); // eslint-disable-line @typescript-eslint/unbound-method | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong, please revert.