Open chenshuai2144 opened 7 years ago
The error appears to be related to TypeScript? I don't think the definitions at https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/reflux have been updated yet for version 6 of reflux.
Also in version 6+ of Reflux you'll probably need to put your values inside the state object. This is how I would updated it:
class StatusStore extends Reflux.Store {
constructor() {
super();
this.listenables = pageAction;
this.state = {
page: location.hash.replace('#', ''),
hashHistory: []
}
}
onPush(newPage) {
if (this.state.page === page) {
return false;
}
LeftMeunAction.hide();
var prevPage = this.state.page;
/*
Note: you should also clone hashHistory (treat it as immutable) if you need to detect changes in React components,
for example state.hashHistory.length !== nextState.hashHistory.length in shouldComponentUpdate
JSON.parse(JSON.stringify()) is a hack to clone an object, but there are other ways to do that :)
*/
var historyClone = JSON.parse(JSON.stringify(this.state.hashHistory));
historyClone.push(prevPage);
this.setState({
page: newPage,
hashHistory: historyClone
});
}
}
国际化
The type definition for Reflux v6.4 has been updated on Jun 26, 2018, it now supports the new class usage of Reflux.
这样写是错误的