nvm use 4
npm run build
node main.js
Created
December 11, 2015 20:57
-
-
Save thom4parisot/a27f0ffffd7655dff730 to your computer and use it in GitHub Desktop.
babel + jsx + virtual-dom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const h = require('virtual-dom/h'); | |
const cx = require('classnames'); | |
const html = require('vdom-to-html'); | |
// | |
class Component { | |
constructor (state) { | |
this.state = Object.assign({}, this.state || {}, state); | |
} | |
} | |
// | |
class Button extends Component { | |
render () { | |
const classNames = cx({ | |
'block__element': true, | |
'block__element--active': this.state.active | |
}); | |
return (<button className={classNames}>{this.state.value}</button>); | |
} | |
} | |
// | |
const b = new Button({ value: 'Hello World', active: true }); | |
console.log(html(b.render())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "vdom-babel", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"build": "babel -o main.js main.jsx" | |
}, | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"babel": "^6.3.13", | |
"babel-plugin-transform-react-jsx": "^6.3.13" | |
}, | |
"dependencies": { | |
"classnames": "^2.2.1", | |
"vdom-to-html": "^2.2.0", | |
"virtual-dom": "^2.1.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment