上QQ阅读APP看书,第一时间看更新
Adding a selected view
This view will register itself with the store and ask for updates to its content. If there are any updates it will be notified and the data from the store will be read and this view will communicate what the store value now is:
// demo/selectedView.js
import store from "./store";
console.log('selected view loaded');
class SelectedView {
constructor() {
this.index = 0;
store.addListener(this.notifyChanged.bind(this));
}
notifyChanged() {
this.index = store.getSelectedItem();
console.log('new index is ', this.index);
}
}
const view = new SelectedView();
export default SelectedView;