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

Custom attribute syntax #8

Open
vldm opened this issue May 19, 2023 · 3 comments
Open

Custom attribute syntax #8

vldm opened this issue May 19, 2023 · 3 comments

Comments

@vldm
Copy link
Collaborator

vldm commented May 19, 2023

Original issue from: stoically#50

I'd like to be able to have custom syntax for attribute keys, to support syntax similar to Angular or Lit:

Angular:

<div  [prop]="foo"  (click)="callback"  [(twoWayBinding)]="bar">

Lit:

<div  .prop="foo"  @click="callback"  ?boolAttibute="biz">

Maybe something similar to transform_block but for attributes.

If this looks like a good idea to you, I might be able to create a PR.

@ilmmatias
Copy link

@vldm This is related to this issue if not actually the same, but would it be possible to support something like attr(block)?
You suggested bind(arg) (e.g. bind(val: u32)) on the prop passing issue, but that syntax doesn't seem to be currently supported by rstml, so my attempt to implement it like that ended up failing.

@vldm
Copy link
Collaborator Author

vldm commented Jun 3, 2023

@yuuma03 hi, yes, currently it is not in master. But i am experiment with it locally. I have pushed branch https://github.com/rs-tml/rstml/tree/add-fn-pattern so you can check it

I haven't created pr, or merged it yet, because need some feedback about idea. Maybe it violate some html/xml parser rule, that i am currently don't know.

I also wasnt sure about design:

  • Should it use paren, or other kind of delimiter, maybe |x:foo| like in closure?
  • Maybe it should be solved in more generic way (to also support syntax from this issue).
  • Maybe we want to compose binding pattern and = value, to parse something like (bind(x:u32)={x}).

But you still can try this branch, i already use it in my pet project, and if idea would be accepted, i can add more tests and merge it as is.

@vldm
Copy link
Collaborator Author

vldm commented Jan 14, 2024

This task and spread syntax looks similar.
Both request changes that adds custom punctuation before or after attribute name.

I don't think it would be possible at this point to support parens/brackets inside attribute names, since that would already be conflicting with binding syntax.

But for other puncts, it would be useful to have a set of name "modifiers", each of which would represent a punctuation and flag that will represent a position in the name.

My propose is to implement a structure that will accumulate all punkts, and use it as prefix and postfix fields in KeyedAttribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants