Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about dispatcher and store #11

Open
aigc-in-all opened this issue May 18, 2016 · 2 comments
Open

about dispatcher and store #11

aigc-in-all opened this issue May 18, 2016 · 2 comments
Assignees

Comments

@aigc-in-all
Copy link

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.

@lgvalle
Copy link
Owner

lgvalle commented May 22, 2016

Can you please link the code involved?

@aigc-in-all
Copy link
Author

aigc-in-all commented May 23, 2016

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

@lgvalle lgvalle self-assigned this May 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants