Coder Social home page Coder Social logo

msoftware / droidflux Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thedumbtechguy/fluxxan

0.0 2.0 0.0 155 KB

DroidFlux is an Android port of the popular Fluxxor library that seeks to implement the Flux Architecture as popularised by Facebook.

License: MIT License

Java 100.00%

droidflux's Introduction

DroidFlux

Android Arsenal

DroidFlux is an Android port of the popular Fluxxor library that seeks to implement the Flux Architecture as popularised by Facebook.

This library is direct port of Fluxxor and works a lot like it. It is currently highly experimental but I wish to develop it into a full fledged library. It is untested and I advise against using it in production.

I currently need help in the following aspects:

  • Writing Tests
  • Proper Concurrency
  • Performance Tuning
  • Documentation

Until that is done, I won't be releasing it on Maven/JCenter.

Version

0.0.2

ChangeLog

####0.0.2

  • Notify store listeners on the UI thread
  • Added getFlux method to Store
  • Synchronized Dispatcher.dispatch method

####0.0.1

  • Initial Code Commit

Installation

Simply clone the project and open in Android Studio. It contains a sample that illustrates a basic use. You can play around with it.

Actions

This object holds all the actions you can take in your App. You can structure this however you wish. It must implement com.whisppa.droidfluxlib.Actions or better still extend com.whisppa.droidfluxlib.impl.AbstractActionsImpl which implements the required interface.

Only Actions should dispatch Payloads. If you need anything done in your app, you call an Action and it does the work on your behalf. Any Asynchronous work must be done in the method before the Payload is dispatched.

public class MyActions extends AbstractActionsImpl {
    public static final String GET_USER = "GET_USER";

    public void getUsers() {
        try {
            mDispatcher.dispatch(new Payload(GET_USER, new Bundle()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Payload

A Payload holds both the action type (A Constant string which Stores can bind to) and data bundle.

Store

A given Store holds some required data. It reacts to dispatched payloads to perform actions. A store returns it's State (any custom object) via getState. It binds to actions via bindAction(String actionType, String methodName). The given method must exist, be accessible (public) and take a single Payload parameter. Stores must implement com.whisppa.droidfluxlib.Store or extend the abstract implementation com.whisppa.droidfluxlib.impl.AbstractStoreImpl.

A store can take listeners of type StoreListener which it notifies of changes to its state using notifyListeners().

A payload will usually maybe carry some data which a Store will use. E.g. A user ID which the store will use in retrieving data from it's backing store. A payload can actually contain the user data which the Store will simply set as state. More examples to come soon.

Stores cannot be asynchronous by nature and must return immediately. Any Asynchronous activity must be done in the Action. Also, the handler method will be run on the UI thread and therefore should return as quickly as possible.

public class MyStore extends AbstractStoreImpl<String> {
    String user = "User: Default";

    public MyStore() {
        try {
            bindAction(MyActions.GET_USER, "getUser");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void getUser(Payload payload) {
        user = "User: " + new Random().nextInt();
        this.notifyListeners();
    }

    @Override
    public String getState() {
        return user;
    }
}

Flux

This is the main Class that holds everything together. This should be the central point for accessing

  • Stores
  • Actions

There should be only one instance of this in your App and the best place to instantiate it is in a Custom Application.

public class MyApp extends Application {

    static Flux<MyActions> DroidFlux;

    @Override
    public void onCreate() {
        DroidFlux = new Flux<MyActions>(new Store[]{new MyStore()}, new MyActions());
    }

    public static Flux<MyActions> getFlux() {
        return DroidFlux;
    }
}

License

The MIT License

droidflux's People

Contributors

thedumbtechguy avatar

Watchers

 avatar  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.