Skip to content

Comments

Feature idea: modifier/node interpolator#441

Open
ansh7432 wants to merge 31 commits intoarmanbilge:mainfrom
ansh7432:fix/node-interpolator
Open

Feature idea: modifier/node interpolator#441
ansh7432 wants to merge 31 commits intoarmanbilge:mainfrom
ansh7432:fix/node-interpolator

Conversation

@ansh7432
Copy link
Contributor

@ansh7432 ansh7432 commented Mar 9, 2025

Add nodes string interpolator for mixing text and dynamic content

Summary

This PR implements the nodes string interpolator feature requested in #401. It enables mixing static text with dynamic content (such as signals and modifiers) in a clean, intuitive way.

Implementation Details

The implementation adds a StringContext extension method called nodes that allows for string interpolation with various types:

Signal[F, String] and Signal[F, ?] for reactive values
Modifier[F, El, ?] for existing modifiers
Product types (tuples and case classes)
Effect types like F[String]
Standard values (using toString)
Each interpolated string becomes a series of text nodes and dynamic content, preserving the reactivity of signals while providing a more ergonomic API.

Example Usage

##Benefits
Improved readability: Code is more concise and follows natural expression patterns
Maintained reactivity: Only the signal parts update when their values change
Type flexibility: Works with various types beyond just Signals
Intuitive syntax: Familiar string interpolation pattern from standard Scala

@ansh7432
Copy link
Contributor Author

ansh7432 commented Mar 9, 2025

Hii @kubukoz @armanbilge please review the PR i had made the changes

@armanbilge
Copy link
Owner

Thanks for the PR! To test it works, can you update the TodoMvc demo app to use this new feature?

@ansh7432
Copy link
Contributor Author

ansh7432 commented Mar 9, 2025

Thanks for the PR! To test it works, can you update the TodoMvc demo app to use this new feature?

Yeah sure making these changes.. :)

@ansh7432
Copy link
Contributor Author

Hii @armanbilge @kubukoz getting some error while implementing the test for nodeinterpolator please go through the code and review it

@kubukoz
Copy link
Collaborator

kubukoz commented Mar 10, 2025

Can you push the code with the broken test? The last CI run is green

@ansh7432
Copy link
Contributor Author

Hi @kubukoz try to add test in todomvc file adding nodesinterpolator please check and review when you have time I've made these changes:

Added the import: import calico.html.nodes
Updated the label in TodoItem to use the interpolator:
label(nodes"${todo.map(.map(.text).getOrElse(""))}")

When compiling, I'm seeing errors related to the nodes string interpolator. Initially, I tried using it with type parameters like nodes[IO]"...", but that caused syntax errors. When removing the type parameters, it still fails to compile.

@armanbilge
Copy link
Owner

@ansh7432 I think your implementation is quite complex. I recommend to start from the initial proposal in #401 (comment) and support additional features one-by-one, instead of all at the same time. That will make it easier to debug.

@ansh7432
Copy link
Contributor Author

Hii @armanbilge @kubukoz implemented nodesinterpolator test in todoMvc and its working fine please check if needs more changes :)

@armanbilge
Copy link
Owner

and its working fine

Hmm, are you sure? I just gave it a try, and the TodoMVC app seems to be broken, I am unable to add any todos 😕

For reference, here is the working example: https://armanbilge.github.io/calico/todomvc/

@ansh7432
Copy link
Contributor Author

ansh7432 commented Mar 11, 2025

image
hii @armanbilge I apologize, please check it once more its working in my local machine now..

@ansh7432
Copy link
Contributor Author

Hi @armanbilge @kubukoz gentle reminder to review this 😊

@ansh7432
Copy link
Contributor Author

Thanks for the review fixing all the things and again raising pr soon 😊

@ansh7432 ansh7432 requested review from armanbilge and kubukoz March 14, 2025 16:30
Co-authored-by: Arman Bilge <armanbilge@gmail.com>
@armanbilge
Copy link
Owner

Nice work, this is much improved! I think like Jakub suggested in #441 (comment), the next step is move more of the interpolation into compile-time.

In general, I think the runtime class checks and casts are going to cause problems down the line - the interpolator should know the types of its inputs at compile-time.

@ansh7432
Copy link
Contributor Author

ansh7432 commented Mar 14, 2025

Nice work, this is much improved! I think like Jakub suggested in #441 (comment), the next step is move more of the interpolation into compile-time.

In general, I think the runtime class checks and casts are going to cause problems down the line - the interpolator should know the types of its inputs at compile-time.

Yeah so looking for this now after working on this would this be able to merge ?

@armanbilge
Copy link
Owner

Now that we've prototyped the idea, let's keep improving it in this PR until it's production-ready 💪

@ansh7432
Copy link
Contributor Author

Yeah sure will working on this @armanbilge 😃

@ansh7432
Copy link
Contributor Author

hii @armanbilge I had updated the PR please look into this.. 😊 please suggest more improvements on this 😀

@ansh7432
Copy link
Contributor Author

Hii @kubukoz @armanbilge please review this :)

@ansh7432 ansh7432 requested a review from armanbilge March 20, 2025 21:50
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.

3 participants