android-flux-todo-app icon indicating copy to clipboard operation
android-flux-todo-app copied to clipboard

about dispatcher and store

Open aigc-in-all opened this issue 9 years ago • 2 comments

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.

aigc-in-all avatar May 18 '16 11:05 aigc-in-all

Can you please link the code involved?

lgvalle avatar May 22 '16 06:05 lgvalle

@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 {}
}

aigc-in-all avatar May 23 '16 07:05 aigc-in-all