đ Virtual DOM for Python
Write declarative layouts in Python, today! :tada:
pip install vdom
vdom.svg
from vdom.svg import svg, circle
svg(
circle(
cy=10,
cx=10,
r=10
),
height=20
)
button
, label
, and style
elementsimg
, input_
) now prevent you from accidentally putting children on them (since that would be totally invalid)Write declarative layouts in Python, today! :tada:
pip install vdom
You can now write:
div(
h1('Woohoo'),
p('it works')
)
Instead of:
div([
h1('Woohoo'),
p('it works')
])
keyword arguments should come after the positional arguments.
All the standard DOM elements are importable from vdom.helpers
(#15)
from vdom.helpers import div, span, p, meter
def happiness(level=90):
smiley = "đ"
percent = level / 100.
if(percent < 0.25):
smiley = "âšī¸"
elif(percent < 0.50):
smiley = "đ"
elif(percent < 0.75):
smiley = "đ"
return span(
p('Happiness ', smiley),
meter(level, min=0, low=25, high=75, optimum=90, max=100, value=level)
)
We've started off some light documentation of how to use vdom
, and we would welcome more examples from you.
Basic tests are set up to ensure you can use vdom
in python2 and python3.
vdom
Write declarative layouts in Python, today! Now with cleaner interfaces that work out of the box. đ
pip install vdom
This cleans up probably the biggest misstep we could have made when starting this which was making a function called createElement
that doesn't actually create the VDOM Element. It creates something more similar to creating a component which can create elements later (it's a factory...).
createElement
is deprecated in favor of createComponent
. We kept it backwards compatible with the last release (0.2), keeping it in for now (it's only been a week, but we might as well be kind).
That being said, there are some niftier helpers you may like better! See below for more.
createComponent
createComponent
is exactly the same as what createElement
did before, with a better name.
>>> marquee = createComponent('marquee')
>>> marquee('woohoo')
<marquee>woohoo</marquee>
h
Wait, did you pick a single letter for a function?
Yes, yes we did. Ok, it's not us. This comes by way of preact
and hyperscript
, allowing you to write condense React.createElement
style writing:
>>> h('div', [h('p', 'hey')])
<div><p>hey</p></div>
We don't have JSX in Python, so this is the closest we can really get. :wink:
The h1
, img
, and other HTML elements are still created here, they're left alone for backwards compatibility. These were put in to be similar to hyperscript-helpers.
Prior to this, you had to wrap VDOMEls in a call to VDOM()
. That's no more, as VDOMElements provide the repr properly now: