-
Notifications
You must be signed in to change notification settings - Fork 9
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
new arg to filter by subclass ref #2105
Conversation
ab3f885
to
c8b1f13
Compare
… the type. Query system doesn't behave well with two types
c8b1f13
to
9f0fe1c
Compare
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 all good, but I think it would be fine to make an exception and not check isInsideAncestorChain
when the type
we're comparing to is the base carddef. isInsideAncestorChain
will end up loading all the cards in the ancestor chain when we already know that all card subtypes descend from card def. In that case, you can just confirm via isCardDef
for the subtype if we're not sure if the type is a card.
packages/base/links-to-editor.gts
Outdated
@@ -143,6 +147,7 @@ export class LinksToEditor extends GlimmerComponent<Signature> { | |||
|
|||
private chooseCard = restartableTask(async () => { | |||
let type = identifyCard(this.args.field.card) ?? baseCardRef; | |||
type = await getNarrowestType(this.args.subclassType, type, myLoader()); |
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.
Alternatively, you can only call this function if a subclassType arg was provided
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.
Actually do you even need to check if the type
is the base CardDef? We know that all cards descend from it, so maybe in that case you can skip loading the whole chain and just use the provided subtype.
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.
Actually do you even need to check if the type is the base CardDef? We know that all cards descend from it, so maybe in that case you can skip loading the whole chain and just use the provided subtype.
I think we do. We need to check if type is base CardDef as a terminating condition to "stop checking".
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.
@burieberry maybe we can talk thru this after standup. Probably some small misunderstanding
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.
@burieberry I have made the change that you have suggested
packages/runtime-common/code-ref.ts
Outdated
async function isInsideAncestorChainOfCardDef( | ||
codeRef: CodeRef, | ||
loader: Loader, | ||
): Promise<boolean | undefined> { | ||
let card = await loadCard(codeRef, { loader: loader }); | ||
if (isCardDef(card)) { | ||
return true; | ||
} | ||
return false; | ||
} |
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 thought about this and I think it would be good to add to this some of your previous logic. This makes sense if the type
we're comparing to is base CardDef, or if we only care that the subtype is a card def, regardless of what the type
we're comparing to is. If type
is not base card def, then we should consider if we want to confirm that subtype
is descended from it. We currently only use this subtype
argument for BoxelSpec, but making this change would allow us to use it in different cases where the type
is not base card def. I'm open to hearing what other people in the team thinks about this.
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.
For context, this is the diff change 02e8408. Previously, we use to have more generic handling of the subtype
packages/runtime-common/code-ref.ts
Outdated
@@ -227,3 +227,27 @@ export function humanReadable(ref: CodeRef): string { | |||
function assertNever(value: never) { | |||
return new Error(`should never happen ${value}`); | |||
} | |||
|
|||
async function isInsideAncestorChainOfCardDef( |
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.
javascript has a similar kind of function called typeof
. maybe that is a clearer name for this method: isTypeOf()
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.
Actually, i take that back, this looks like a synonmym for isCardDef. let's just overload that specific method so it takes either a codeRef and loader and an already running card:
export function isCardDef(card: any): card is typeof CardDef;
export function isCardDef(codeRef: CodeRef, loader: Loader): boolean
export function isCardDef(cardOrCodeRef: any, loader?: Loader): boolean { ... }
(not too sure how all the type assertion works out since you can't assert a CodeRef param is a CarDef). if the overload doesn't work, at least try to name this is similar as you can to isCardDef
, so that it is clear that we are using the same semantics.
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.
Ahh ok I think this worked but loadCard is async so I used .then within the isCardDef implementation. I also added a note on using isCardDef
in getNarrowestType
packages/base/card-api.gts
Outdated
Named: { | ||
format?: Format; | ||
displayContainer?: boolean; | ||
subclassType?: ResolvedCodeRef; |
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.
Perhaps typeConstraint
or allowedClass
would be a better name?
Co-authored-by: Luke Melia <luke@lukemelia.com>
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.
Looks much better
Purpose of this PR is to enable spec to choose linkedExamples that link by type
API change