Giter Site home page Giter Site logo

Comments (5)

markuswustenberg avatar markuswustenberg commented on August 17, 2024

Hi @eduardolat, thank you for the issue!

The NodeFunc, which is the function that renders an element in El, already satisfies the fmt.Stringer interface: https://github.com/maragudk/gomponents/blob/main/gomponents.go#L58

So you can do something like using fmt.Sprint to render your nodes to a string: https://go.dev/play/p/c-nSNHUKaAH

from gomponents.

eduardolat avatar eduardolat commented on August 17, 2024

Thank you for your kind response.

Indeed I have realized that NodeFunc does satisfy the interface, however it is a bit counterintuitive that Node does not do it.

Is there any reason why Node doesn't have that method?

It would be very easy to simply do a mypage().String() which can easily suggested by the code editor instead of checking the code in the repository to see how it is implemented and notice that there is a NodeFunc function that does the task.

It is also not so intuitive due to the fact that you are always working with Node and not with NodeFunc, so you usually do not have knowledge of this function.

Would it be a good idea to add .String() to Node?
Or is it better to document NodeFunc and leave Node as is?

I leave you a couple of examples of how it is not intuitive to render as a string.

Screenshot 2024-02-11 170331
Screenshot 2024-02-11 165316

Thanks for your time!!

from gomponents.

markuswustenberg avatar markuswustenberg commented on August 17, 2024

I think of it this way: The only thing that is required for a component to be able to render is to satisfy the Node interface. Implementations of that interface, such as NodeFunc, may also satisfy the fmt.Stringer interface, but that's up to the concrete implementation.

If someone writes a large component where it wouldn't make sense to keep the whole thing in RAM (say, a large HTML document or a complex SVG), I don't want to force it on them to implement a String() string function. I like the streaming-based design that io.Writer offers. I think it's quite Go-idiomatic.

So while I think I understand what you mean, I don't want to add anything to the Node interface at this point. I would suggest you write a helper function for your own purposes that takes any Node and uses a strings.Builder to create a string.

I hope this makes sense. šŸ˜Š

from gomponents.

eduardolat avatar eduardolat commented on August 17, 2024

It makes all the sense in the world, now I am very clear about your decision to do it that way, I will continue to happily use my helper when I need it.

Thank you very much for this great project.

from gomponents.

markuswustenberg avatar markuswustenberg commented on August 17, 2024

Iā€™m glad to hear that. šŸ˜Š

from gomponents.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.