Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vDOM and 'style' h tag #384

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

vDOM and 'style' h tag #384

wants to merge 6 commits into from

Conversation

sebjwallace
Copy link

vDOM is just a bootstrap object to initialize a virtual dom, and to provide a render method to update the virtual dom. This is entirely for convenience for using the virtual dom out-the-box without setup. This is just for browser use, as it requires the document object.

// example when virtual-dom is imported via script tag
var vDOM = new virtualDOM.vDOM()
vDOM.render(vTree)

The styles h tag renders a vNode with 'STYLE' tag and a child vText node with the text content of parsed styles.

h('style', {  '#foo':{color:'blue',weight:500}  })

Will render to a vText child with text:

#foo{color:blue;weight:500}

camelCasing is also available:

h('style', { '.bar':{backgroundColor:'grey'} })
// .bar{background-color:grey}

This is useful if a stylesheet is needed to be built dynamically within javascript. General classes, animations, css events (ie hover), even media queries can be declared using this tag.

Instead of writing setup code to load and update the virtual dom, just instantiate vDOM and call vDOM.render( newTree ) to diff and patch.

This is for browser-use only, as the 'document' object is called.
A wrapper object to instantiate a virtual dom
@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 97.537% when pulling 2d013f7 on sebjwallace:master into dcb8a14 on Matt-Esch:master.

@ajoslin
Copy link

ajoslin commented Apr 21, 2016

Hey @sebjwallace. it looks like you should make a separate module for this. virtual-dom's core needs to stay as small as possible, and this is sugar instead of core functionality.

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