写了一个很简单的reflux练习,浏览器报错:[object Object] is missing a listen method ,找不到原因在哪,求各位帮助,非常感谢!
store.js:
Reflux.createStore({
items:[],
listenables: [actions],
onGetAll () {
this.trigger({list:this.items});
},
onAdd(item){
this.items.push({name:item});
this.trigger({list:this.items});
},
onRemove(i){
this.items.remove(i);
this.trigger({list:this.items});
}
});
actions.js:
export default Reflux.createActions(['getAll','add','remove']);
component.js
export default class Todo extends React.Component{
componentDidMount() {
actions.getAll();
}
add(){
var item = this.refs.item.value;
this.refs.item.value='';
actions.add(item);
}
remove(i){
actions.remove(i);
}
render() {
//items用于乘放li的集合
let items;
if (this.state.list) {
items = this.state.list.map( (item,i) => {
return <li key = {i}>
{item.name}
<button onClick = {this.remove.bind(this,i)}>remove</button>
</li>
})
}
return (
<button onClick={this.add.bind(this)}>add</button>
)
}
}
ReactMixin.onClass(Todo, Reflux.connect(store));