Comments (5)
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.
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.
Thanks for your time!!
from gomponents.
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.
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.
Iām glad to hear that. š
from gomponents.
Related Issues (20)
- Fragments HOT 6
- Links? HOT 1
- Why g.Map doesn't also do g.Group? HOT 2
- Generics g.Map performance HOT 7
- Use Custom attributes & alpine js HOT 3
- component specific css and js HOT 6
- Use with tinygo HOT 3
- Merge multiple occurrences of the `class` attribute HOT 5
- Proposal: Re-export packages with shorter names (g, h, c) HOT 3
- Inline if with nil pointer HOT 8
- Why can't a group be rendered? HOT 11
- Add lib to awesome Go HOT 1
- Remove fmt.Stringer support? HOT 3
- Handling internationalization HOT 9
- trigger an error on duplicate attributes HOT 3
- Make Group renderable
- HTML -> gomponents converter tool HOT 2
- Label can be an attribute as well HOT 2
- Missing list attribute HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gomponents.