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

Spread JS event map #612

Closed
iamajoe opened this issue Mar 12, 2024 · 6 comments
Closed

Spread JS event map #612

iamajoe opened this issue Mar 12, 2024 · 6 comments

Comments

@iamajoe
Copy link
Contributor

iamajoe commented Mar 12, 2024

Sorry in advance in case I have missed an issue related to this.

There are cases where a map[string]templ.ComponentScript might make sense but spreading or iterating is not possible on the attributes side. Tried to do a spread with templ.Attributes but those are not templ scripts so it makes sense that they do not work.

jsMap := map[string]templ.ComponentScript{
  "onclick": alert(),
}

Example A (spread):

<button { jsMap... }>Foo</button>

Example B (for):

<button
for evt, fn := range jsMap {
  {evt}={fn}
}
>Foo</button>

Personally I think it would be better to support a for under attributes. Also, a for even for templ.Attributes would be interesting.

@alehechka
Copy link
Contributor

I have a PR open that adds support for ComponentScripts within the templ.Attributes. There hasn't been much action for review, but with more interest in the feature maybe it can move over the line.

#595

@iamajoe
Copy link
Contributor Author

iamajoe commented Mar 15, 2024

Nice. I would say it is still not the best interface since my go to would be to use go syntax but a solution at least and also the "basis" since attributes is like the barebones option.

@joerdav
Copy link
Collaborator

joerdav commented May 31, 2024

I'm going to close this issue for now as script templates are deprecated, we are looking into creating examples of better ways to interact with js in templ, which will hopefully make your use cases easier to implement.

@joerdav joerdav closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2024
@iamajoe
Copy link
Contributor Author

iamajoe commented May 31, 2024

I'm going to close this issue for now as script templates are deprecated, we are looking into creating examples of better ways to interact with js in templ, which will hopefully make your use cases easier to implement.

Why is it deprecated? I am actually using it quite a lot. The idea now is to substitute by the script tags, sure works about the same but think about a button onclick for example, it is easier to set through a ComponentScript. Do you have an issue related to this deprecation I could read?

@joerdav
Copy link
Collaborator

joerdav commented May 31, 2024

@iamajoe not yet. Currently there is one for css components, the reasoning is very similar. #740

@joerdav
Copy link
Collaborator

joerdav commented May 31, 2024

The deprecation itself happened under #739

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

3 participants