Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@alfonsogarciacaro
Copy link
Contributor

Because directives can be used with standalone templates, users can get confused when animate is not working (I had to debug the code to find the problem). Not sure if this the best way to do the check but it'd be nice to offer a more meaningful error when the host LitElement cannot be found. It'd be also desirable to put in the README, I can see a PR to include a mention if that's OK.

@changeset-bot
Copy link

changeset-bot bot commented Sep 28, 2021

⚠️ No Changeset found

Latest commit: fba16cc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@google-cla google-cla bot added the cla: yes label Sep 28, 2021
if (firstUpdate) {
this._host = part.options?.host as LitElement;
if (this._host == null) {
throw new Error("animate directive must be used in a LitElement");
Copy link
Collaborator

Choose a reason for hiding this comment

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

The host just has to implement the ReactiveControllerHost interface. So it can be a ReactiveElement or other implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for checking @justinfagnani! Yes, that's what I thought at the beginning. I've implemented HookComponents (similar to VirtualComponent in Haunted) using AsyncDirective in lit 2, and tried to implement the ReactiveControllerHost interface. But this was not enough for animate because it depends on methods that are not on the interface but come from ReactiveElement class, like hasUpdated or updateCompleted:

protected get isHostRendered() {
const hostRendered = renderedHosts.has(this._host!);
if (!hostRendered) {
this._host!.updateComplete.then(() => {
renderedHosts.add(this._host!);
});
}
return hostRendered;
}

Actually I wanted to ask about this, because if Reactive Controllers stick to the ReactiveControllerHost interface they could be used more broadly (e.g. you could create a React hook that accepts reactive controllers), but if controllers are going to depend on LitElement at the end this won't be the case (and it makes the ReactiveControllerHost interface somewhat useless).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, seems I misread the docs and updateComplete is actually part of ReactiveControllerHost interface, but not hasUpdated so I've sent a PR to replace it: #2239

@augustjk
Copy link
Member

closing in favor of #2239

@augustjk augustjk closed this Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants