Skip to content

Add capacity to pass bound variables for attribute map #8

Open
Sleepful wants to merge 5 commits intoroman01la:mainfrom
Sleepful:jv-2025-12-27-dev-0.3
Open

Add capacity to pass bound variables for attribute map #8
Sleepful wants to merge 5 commits intoroman01la:mainfrom
Sleepful:jv-2025-12-27-dev-0.3

Conversation

@Sleepful
Copy link
Contributor

@Sleepful Sleepful commented Dec 29, 2025

In short, previously it was possible to pass an attribute map only by using the map literal, such as:

  • ($ my-component {:class "this-is-literal"})

this changes makes it such that the map can be passed as a variable, basically

  • ($ my-component [my-attribute-map-variable])

You will notice that I am wrapping the attribute map in a vector in order to hint the macro that the value is bound at runtime.

To understand this change better, please look at:

  1. README
  2. test/vitest/basic_component.cljc
    a. The (render #($ label-with-attrs [attrs] title input) line shows the usage, rather contrived.

@roman01la
Copy link
Owner

roman01la commented Dec 29, 2025

I don’t like the vector syntax. Instead it should be possible to just provide props as usual and interpret them at runtime, this is how it’s done in all react wrappers

@Sleepful
Copy link
Contributor Author

Sleepful commented Dec 29, 2025

UPDATE: I think I found a solution following the idea at the end of this comment, will push update soon.


@roman01la I don't like the vector that much either. How could that be done?

Right now the issue is that during compilation time, the bound attributes are indistinguishable from child nodes. Additionally, the child nodes are wrapped in a callback function. This means that at runtime, I have not found a way to differentiate between a bound attribute map and a child node.

Do you see the problem that I see?

wrap-children is the function that turns the args into a callback:

(defn- wrap-children [children]

Perhaps an idea would be to leave the child-wrapping for runtime instead of compilation, that way the value type can be checked at runtime for something that indicates whether an attribute map is currently being passed. But I dunno, there might be better ways. What do you think?

@Sleepful
Copy link
Contributor Author

@roman01la updated :) LMK your thoughts!

@Sleepful Sleepful force-pushed the jv-2025-12-27-dev-0.3 branch 2 times, most recently from 232f0c8 to 676da24 Compare December 30, 2025 09:52
@Sleepful Sleepful force-pushed the jv-2025-12-27-dev-0.3 branch from 676da24 to 8ce2ad0 Compare December 30, 2025 09:55
@Sleepful Sleepful force-pushed the jv-2025-12-27-dev-0.3 branch 2 times, most recently from 609570c to b5ebb08 Compare December 30, 2025 10:42
…the signals will be resolved to values (and thus lose its signal reference) before they can be captured by a wrap-component-props function
@Sleepful Sleepful force-pushed the jv-2025-12-27-dev-0.3 branch from b5ebb08 to 031580b Compare December 30, 2025 10:43
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

Successfully merging this pull request may close these issues.

2 participants