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

Just a small town boy living in a ember modifier world #179

Merged
merged 5 commits into from
Mar 26, 2019

Conversation

snewcomer
Copy link
Collaborator

@snewcomer snewcomer commented Mar 24, 2019

This is not the final product, but the start of how one could use a modifier inside a component.
No feature added. Required a slight refactor to the mixin but seems like the easiest path for now if people want to use an element modifier inside a component (w/ or w/o a tagName btw!)

In the example in the dummy app, it uses did-insert from @ember/render-modifiers and adds the specific element to the pool of elements that we watch.

You could possibly use this to watch multiple nodes.

export default Component.extend(InViewportMixin, {
  didInsertHeader() {}
  didInsertFooter() {}
  didInsertHeroImage() {}
});

although for this to work with multiple items, we would need to figure out what to do when triggering didEnterViewport

See dummy/components/my-modifier.js for the example.

close #109 close #177

@snewcomer
Copy link
Collaborator Author

Follow up will include a better manager for the elements on the page.

```

```hbs
<div {{did-insert this.didInsertNode this}}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that it uses the existing implementation in a clean way, but I wonder if there's a way to write the modifier such that it doesn't need the entire component instance? I had thought that the benefit of modifiers is that they can operate on DOM nodes independently of their associated component classes.

My initial thought at implementing (before i knew about @ember/render-modifiers, was to wire up an IntersectionObserver with the element directly.

I don't quite get how modifier managers work at the moment, so I wasn't able to understand what the did-insert modifier is actually doing under the hood

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Added a note about a future add did-enter-viewport modifier + a service (instead of a mixin). Will think about this over the following months. Thanks for taking a look!

@snewcomer snewcomer merged commit 0dc7040 into master Mar 26, 2019
@snewcomer snewcomer deleted the sn/start-modifier branch March 26, 2019 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: did-enter-viewport and did-exit-viewport element modifiers
2 participants