Code Monkey home page Code Monkey logo

ti-flux's Introduction

Titanium-Flux

PoC App for Flux architecture within Titanium+Alloy Projects.

Table of Contents.

Running the app

Use the same steps as any other Titanium+Alloy app:

# Optional: Compile alloy to generate the plug-in.
$ alloy compile --config platform=[ios|android]

# Run the app in simulator
$ [appc] ti build -p [ios|android]

Core Flux components

This projects aims to move away from the MVC architecture and use Flux instead. Refer to Facebook's site and its examples to learn more about it.

Some new rules that must take place in order to not break the architecture are:

Dispatcher.

This is the main mediator between the Actions and Stores, all actions must be dispatched and the dispatcher will be in charge of sending them to the different stores in the app.

  • Should live under app/lib/utils/dispatcher.

  • There must not be more than 1 dispatcher living in the app.

  • Should be a singleton instance.

Stores.

Each one contains a representation (as a plain JS Object) of one part of the app.

  • All stores should live under app/lib/stores/.

  • All stores should contain app/lib/utils/store as it's composed parent.

  • All stores should be singleton instances.

  • Any change to a store's inner state must be done through an action in the dispatcher. Altering the store's state by using private or public or private functions is forbidden.

  • All business rules and functionality that is not UI/UX related must live in the stores.

Actions.

Plain JS Object that represent the idea of a change in one or more stores.

  • All actions should live under app/lib/actions/.

  • All actions could be grouped by stores, screens or a single singleton with all the app's actions. Just make sure you follow the project's spec.

  • All actions should be singleton instances.

  • Actions should not include references to the stores directly.

  • All actions must be invoked from a file inside the actions/ folder.

     // Avoid
    
     // Controller.js
     $.someButton.addEventListener('click', function(_evt) {
     	Dispatcher.dispatch({
     		type: 'SOME_BUTTON_CLICK',
     		tag: _evt.source.tag
     	});
     });
     // Use instead
    
     // Controller.js
     $.someButton.addEventListener('click', function(_evt) {
     	Actions.buttonClick(_evt.source.tag);
     });
    
     // actions/actions.js
     function buttonClick(_tag) {
     	Dispatcher.dispatch({
     		type: 'SOME_BUTTON_CLICK',
     		tag: _tag
     	});
     }

Views.

Regular Alloy Controllers that serve as mediators for the changes in the stores and updates in the UI components they declare. Not all Controller should be linked with stores or the dispatcher, but only those that will handle a whole screen or "Containers".

  • All Containers should include a Ti.UI.Window or equivalent as the top-level container.

  • All Controllers must declare a render(_props) function where all UI updates should be declared.

  • All UI updates must live in the render(_props) function or a private function called from it.

  • All UI updates that don't require an action to trigger (i.e UI/UX workarounds, cosmetic changes) must be declared using container.setState().

ti-flux's People

Contributors

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