-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add typescript friendly mixins #85
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import animatedRouteMixin from './animated-routing-mixin.js'; | ||
function animatedRoutingMixin(Superclass, className) { | ||
return animatedRouteMixin(Superclass, className); | ||
} | ||
export default animatedRoutingMixin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {type LitElement} from 'lit'; | ||
import {type Constructor, type RoutingMixinInterface} from './routing.mixin.js'; | ||
import animatedRouteMixin from './animated-routing-mixin.js'; | ||
|
||
function animatedRoutingMixin<T extends Constructor<LitElement>>(Superclass:T, className:string) { | ||
return animatedRouteMixin(Superclass, className) as unknown as Constructor<RoutingMixinInterface> & T; | ||
} | ||
|
||
export default animatedRoutingMixin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import BasicRoutingInterface from './routing-interface.js'; | ||
import routingMixin from './routing-mixin.js'; | ||
const RoutingMixin = (superclass) => { | ||
return routingMixin(superclass); | ||
}; | ||
//exporting BasicRoutingInterface for backward compatibility - don't break consumer imports | ||
export { RoutingMixin, BasicRoutingInterface }; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,16 @@ | ||||||
import BasicRoutingInterface from './routing-interface.js'; | ||||||
import type { Context } from './page.js'; | ||||||
import type RouteTreeNode from './route-tree-node.js'; | ||||||
import type { LitElement } from 'lit'; | ||||||
import routingMixin from './routing-mixin.js'; | ||||||
export type Constructor<T = {}> = new (...args: any[]) => T; | ||||||
export declare class RoutingMixinInterface { | ||||||
routeEnter(currentNode: RouteTreeNode, nextNodeIfExists: RouteTreeNode | undefined, routeId: string, context: Context): Promise<boolean | void>; | ||||||
routeExit(currentNode: RouteTreeNode, nextNode: RouteTreeNode | undefined, routeId: string, context: Context): Promise<boolean | void>; | ||||||
} | ||||||
const RoutingMixin = <T extends Constructor<LitElement>>(superclass: T) => { | ||||||
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. Same here. Should this be specific to
Suggested change
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. This was something we discovered in origin. If we don't use LitElement as the super class we get linter errors when using the lifecycle methods like connectedCallback etc https://lit.dev/docs/composition/mixins/#mixins-in-typescript |
||||||
return routingMixin(superclass) as unknown as Constructor<RoutingMixinInterface> & T; | ||||||
}; | ||||||
|
||||||
//exporting BasicRoutingInterface for backward compatibility - don't break consumer imports | ||||||
export { RoutingMixin, BasicRoutingInterface }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": false, | ||
"emitDeclarationOnly": false, | ||
}, | ||
"include": ["lib/routing.mixin.ts", "lib/animated-routing.mixin.ts"], | ||
} |
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.
Should this be specific to
LitElement
?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.
I would think so, but there are some downstream (platform-tools) components that extend this mixin that complain when using
LitElementHTMLElement. I know it's not ideal to be restricted to LitElement, but I don't believe that we'll be using any other library for the foreseeable future.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.
i commented below but without the LitElement as the extended class, it causes typescript errors when using the lifecycle methods. @barronhagerman @jrobinson01