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

Selectors: recursive mixin check? #2228

Open
kubukoz opened this issue Apr 4, 2024 · 1 comment
Open

Selectors: recursive mixin check? #2228

kubukoz opened this issue Apr 4, 2024 · 1 comment
Labels
feature-request A feature should be added or improved.

Comments

@kubukoz
Copy link
Contributor

kubukoz commented Apr 4, 2024

Hi! I was wondering if there's a way to write a selector that checks if the given shape has a mixin... but checking recursively.

For example, consider this model:

$version: "2"

namespace demo

@mixin
structure MyMixin {}

@hasMyMixin
@mixin
structure Direct with [MyMixin] {}

// structure Indirect with [Direct] {}

@trait(selector: ":test(-[mixin]-> structure [id = 'demo#MyMixin'])")
structure hasMyMixin {}

In its current state, it's valid. However, if you uncomment Indirect it no longer matches (it inherits the hasMyMixin trait, but that fails to validate on Indirect due to the mixin being transitive).

Would it make sense to expand the mixin relationship, or provide a recursive variant of -[...]->? Perhaps a "forward directed recursive neighbor" syntax, like -[...]~>?

Is there a better, existing way to do what I'm looking for? (without resorting to Java)

@kubukoz kubukoz changed the title Recursive mixin check? Selectors: recursive mixin check? Apr 4, 2024
@mtdowling
Copy link
Member

Maybe we could add a synthetic “transitiveMixin” relationship available to selectors which includes direct and transitive mixins. Or maybe a :hasMixin(a, c, c) function that returns true if all mixins are present on a shape. I like the relationship but we’d need to see how disruptive it is vs a function.

@JordonPhillips JordonPhillips added the feature-request A feature should be added or improved. label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

3 participants