react wrapper and template component generating command.
add backbone like events with dom-delegate
.
add helper for nested components like pubsub event etc.
flux framework is too huge(overdone) for me.
npm i reactro -D
app.js (will compile by browserify)
var reactro = require('reactro');
var rootComponent = reactro.createRootComponent({
template: require './template',
templateData: {
hello: 'Hello',
SubComponent: reactro.createSubComponent({
template: require './sub_template'
})
}
});
reactro.render('#container', rootComponent);
template.rjade (use react-jadeify)
.hello= hello
SubComponent(world="world")
sub_template.rjade (use react-jadeify)
.world= props.world
index.html
<!DOCTYPE html>
<html>
<body>
<div id="container"></div>
<script src="app.js"></script>
</body>
</html>
React.createClass wrapper.
return root component object.
can use React.createClass opts.
if doesn't set displayName, overwrite displayName. will use for namespace.
set React.createElement
can set data for template resource.
props and root state will be set automatically.
so can't use props and state keyword.
set css string. It will be added into html head automatically when it will be needed. it needs name option if you use this featuer.
can add DOM events and pubsub events.
{
events: {
// pubsub event
subscribe: {
'event type': function(param){}
},
// dom event
dom: {
'type; delegate-selector': function(e){},
'type type2; delegate-selector': function(e){}
}
}
}
React.createClass wrapper.
return sub component object.
can use React.createClass opts.
same as createRootComponent.
same as createRootComponent.
same as createRootComponent.
almost same as createRootComponent.
but can add only DOM events and can omit dom
keyword.
{
events: {
'type; delegate-selector': function(e){},
'type type2; delegate-selector': function(e){}
}
}
ReactDom.render wrapper.
render component into DOM element selected by selector.
component will be converted to element with props.
ReactDomServer.renderToString wrapper. component will be converted to element with props. dummy RootComponent will be generated when current component is SubComponent or state will set and then state will be used as RootComponent state for component.
publish event to root component's subscriber.
publish ailas.
get dom element by ref.
if you don't use ref like find()
, component dom element is returned.
get root state object.
of course can use returned React.createClass's properties.
can change template resources.
but can't use props and state keyword.
use reactro
command or copy tmpl
directory.
you can choose way of calling local command below.
$(npm bin)/reactro
# add below code to .*rc(.zshrc etc.)
npmbin(){[ $# -ne 0 ] && $(npm bin)/$*}
npmbin reactro
npm i npmbin -g
npmbin reactro
cd /path/to/put/component/dir
npmbin reactro create name=component_name root
generated files into /path/to/put/component/dir/component_name
cd /path/to/put/component/dir
npmbin reactro create name=component_name
generated files into /path/to/put/component/dir/component_name
- add more vurius type tmplate for generate command
- add interactive mode to generate command
- add config setting to generate command
- more support for nested components include root nesting