如下代码是reflux 的骨架
import React from 'react';
import Reflux from 'reflux'
var ReactDOM = require('react-dom');
var mainAction = Reflux.createActions([
'sayHello'
]);
var mainStore = Reflux.createStore({
listenables: [mainAction],
getInitialState:function(){
return {name:"default"}
},
data: {},
onSayHello: function (val) {
this.data.name = "hello " + val;
this.trigger(this.data);
}
})
var HelloWorld = React.createClass({
mixins: [Reflux.connect(mainStore, "xixi")],
say: function () {
mainAction.sayHello("lili");
},
render: function () {
return <div>
<a onClick={this.say}>点击触发</a>
<div >{ this.state.xixi.name}</div>
</div>
}
})
ReactDOM.render(
<HelloWorld />
, document.getElementById('J_contentContainer'))