Coder Social home page Coder Social logo

androidflux's Introduction

AndroidFlux

标签(空格分隔): android flux greenrobot eventbus


关于android上的flux实现请看android-flux-todo-app, 这个例子中使用的是otto eventbus,如果遇到网络请求等异步线程的话,需要自己来做这块,他的建议是放在ActionsCreator来做异步线程操作,然后再传到主线程中执行Store操作,然后再到View。这样感觉有点别扭,感觉更好的方式应该是把Store操作放在异步线程中。

greenrobot的Eventbus有个非常好的特性,就是支持Event是在那个线程中执行,比如主线程或者后台线程等。所以这里可以很方便的指定Store的执行在后台线程。

@Override
public void onEventAsync(Action storeAction) {
    long id;
    switch (storeAction.getType()) {
        case TodoActions.TODO_CREATE:
            String text = ((String) storeAction.getData().get(TodoActions.KEY_TEXT));
            create(text);
            try {
                Thread.currentThread().sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            emitStoreChange();
            break;
    }
}

Store操作完之后通知View更新时指定Event在主线程中执行。

public void onEventMainThread(UIUpdateEvent event) {
    updateUI();
}

Android Flux

androidflux's People

Contributors

dengyin2000 avatar

Watchers

 喵叔catuncle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.