Comments (9)
Oh yeah, well that can't work, there is no root node to attach the 2 divs to. Maybe the buildHtml that only takes children is a bad idea. :-)
from karax.
FYI: Inspired by Karax, I wrote a similar DSL to generate SVG files/animations. As an experiment I modified the DSL in a way that the main buildSvg
macro returns a seq[Node]
making it possible to handle flat structures in general. Maybe this would work for Karax as well? If you are interested here is the macro.
from karax.
I'm going to close this for now due to inactivity. It sounds like this may be able to be supported in the future, but is not currently. Please feel free to re-open and comment if you want to discuss further!
from karax.
Huh? Pretty sure I have code like this.
from karax.
Hm, okay not sure what could be different. Here's my full example to reproduce:
include karaxprelude
proc renderer(): VNode =
result = buildHtml():
tdiv():
text "test"
tdiv():
text "test"
setRenderer renderer
Running with updated karax & nim devel branches this afternoon. And the output of running with -d:debugKaraxDsl
:
let tmp67004 = tree(VNodeKind.tdiv)
add(tmp67004, text "test")
tmp67004
let tmp67005 = tree(VNodeKind.tdiv)
add(tmp67005, text "test")
tmp67005
reproduce.nim(4, 21) template/generic instantiation from here
/home/fabian/.nimble/pkgs/karax-0.1.0/karaxdsl.nim(62, 23) Error: expression 'tmp67011' is of type 'VNode' and has to be discarded
Strange that the symbol is not actually a symbol of the macro.
from karax.
Shouldn't there be the main/global entry point of the app <div id="ROOT"></div>
?
A use case for a "multiple children buildHtml" would be:
proc renderList(): VNode =
# don't want to make a decision about the container here
result = buildHtml():
tdiv():
text "child 1"
tdiv():
text "child 2"
proc renderer(): VNode =
result = buildHtml():
tdiv():
renderList()
aDifferentContainer():
renderList()
This is by the way one of the limitations in Vue (each component must have a single root) and often results in wrapping things in slightly annoying dummy divs.
from karax.
This is by the way one of the limitations in Vue (each component must have a single root) and often results in wrapping things in slightly annoying dummy divs.
We can perhaps introdue a special VNodeKind.unnest
that is embedded into the parent node, but this is more complex than it sounds. :-(
from karax.
Yes, this is probably not so easy. The question is whether a VComponent
should allow for unnested nodes as well, which looks complicated to me. I think it would be an acceptable compromise the require VComponents
to be nested, but solve the problem at least for buildHtml
to make factoring out view elements easier. I had two ideas to solve this, but I didn't think them through yet.
The first idea was to fully switch to lists of nodes, because html itself is always a list of nodes within <body></body>
. This would mean for instance to define type VNodes: seq[VNode]
, change the signature to buildHtml(): VNodes
, and the renderer would return VNodes
. Whenever the karaxdsl comes across a VNodes
element it iterates over it and appends all children. Not sure how feasible this is though.
The other idea is to stay with a single VNode
return type, but make it easier to pass the context (or parent/currentNode) to sub-view elements. If the karaxdsl would inject a name like currentNode
exposing the context, the example from above could be solved like that:
proc renderList(parent: VNode): VNode =
# don't want to make a decision about the container here
# solved by forwarding the parent to buildHtml
result = buildHtml(parent):
tdiv():
text "child 1"
tdiv():
text "child 2"
proc renderer(): VNode =
result = buildHtml():
tdiv():
renderList(currentNode)
aDifferentContainer():
renderList(currentNode)
This might clash (or rather confuse people) with the current overload of buildHtml
to support a tag as its first parameter. Personally have never seen a big need for this, at least not, if the following two are equivalent anyway:
# Writing the root tag in the body looks good to me
result = buildHtml():
tdiv(id="A"):
tdiv(id="sub"):
text "a"
# Do we need support for this, any benefit?
result = buildHtml(tdiv(id="A")):
tdiv(id="sub"):
text "a"
This second solution should work fine for inner levels -- on the outermost level it could be tricky if it requires e.g. a dummy parent.
from karax.
I second this feature.
from karax.
Related Issues (20)
- Wrong `app.js` directory (`karun`) HOT 1
- Delay in redrawing dom HOT 6
- buildHtml does not capture closure variables HOT 2
- Broken functionalities when karax used with grammarly or languagetool (and possibly other extensions) HOT 8
- How to run a function on onclick event in a button? HOT 4
- Boolean Attributes in DSL HOT 6
- Event example does not work HOT 8
- Release 1.2.3 HOT 5
- view doesn't update when changing state in setInterval HOT 3
- IndexDefect on array HOT 3
- Karax input text becoming null HOT 1
- Async karax? HOT 3
- Empty content editable raises an error HOT 1
- How to attach and detach a custom a `Node` to the karax dom? HOT 1
- Karax does not update event handlers HOT 4
- stack size exceeded error on js target HOT 1
- `verbitam` content is appended every time it changes HOT 1
- runtime error on redraw in `removeAllEventHandlers` proc HOT 2
- SVG rendering HOT 2
- 1.3.2 has a tag and release, but karax.nimble version still 1.3.1 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 karax.