Skip to content

Directives that are Controllers--Examples? #4042

Answered by augustjk
chen-ye asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think we have an example in the docs site but the @lit-labs/motion package's animate directive is written as a controller directive.

override update(part: AttributePart, [options]: Parameters<this['render']>) {
const firstUpdate = this._host === undefined;
if (firstUpdate) {
this._host = part.options?.host as LitElement;
this._host.addController(this);
this.element = part.element;
nodeToAnimateMap.set(this.element, this);
}
this.optionsOrCallback = options;
if (firstUpdate || typeof options !== 'function') {
this._setOptions(options as Options);
}

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@chen-ye
Comment options

Answer selected by chen-ye
Comment options

You must be logged in to vote
4 replies
@tbroyer
Comment options

@justinfagnani
Comment options

@augustjk
Comment options

@bennypowers
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants