android-flux-todo-app
android-flux-todo-app copied to clipboard
about dispatcher and store
As shown, all calls are one-way, but in your code is : View -> Actions Creator -> Action -> Dispatcher -> Store -> Dispatcher -> View. which calls the dispatcher in TodoStore not feeling well.
Can you please link the code involved?
@lgvalle
Perhaps this is better?
public class TodoActivity extends AppCompatActivity {
private void initDependencies() {
//dispatcher = Dispatcher.get(new Bus());
dispatcher = Dispatcher.get();
actionsCreator = ActionsCreator.get(dispatcher);
// todoStore = TodoStore.get(dispatcher);
todoStore = new TodoStore();
dispatcher.register(store);
}
@Override
protected void onResume() {
super.onResume();
// dispatcher.register(this);
// dispatcher.register(todoStore);
store.register(this);
}
}
public abstract class Store {
// final Dispatcher dispatcher;
private static final Bus bus = new Bus();
/* protected Store(Dispatcher dispatcher) {
this.dispatcher = dispatcher;
}*/
void emitStoreChange() {
// dispatcher.emitChange(changeEvent());
this.bus.post(changeEvent());
}
public void register(final Object view) {
this.bus.register(view);
}
public void unregister(final Object view) {
this.bus.unregister(view);
}
abstract StoreChangeEvent changeEvent();
public abstract void onAction(Action action);
public interface StoreChangeEvent {}
}