Giter VIP home page Giter VIP logo

simflux's Introduction

simflux

Framework-agnostic, simple Flux wrapper on top of Facebook's Flux

simflux-viz

simflux-viz is a chrome extension and visualization library for simflux that aids developers to understand application flow.

how?

var dispatcher = new simflux.Dispatcher();

// an object qualifies to be a store if it has methods
// named the same as the actions it should handle
var appStore = {
  todos: [],
  addTodo: function(todo, priority) { 
    dispatcher.waitFor([otherStore, anotherStore]);
    this.todos.push({
      todo: todo,
      priority: priority
    });
  },
  removeTodo: function(todo) { ... }
}

// register appStore with Flux
dispatcher.registerStore(appStore);

// all async ops should be handled by the Action Creator
var actionCreator = {
  addTodo: function(todo, priority) {
    doSomethingAsync.then(function() {
      dispatcher.dispatch('addTodo', todo, priority);
    });
  }
}

// in the view: do something!
actionCreator.addTodo({ todo: 'My Todo' }, 'top priority');

why?

  • Less boilerplate
  • Easier to read

differences

dispatch

Flux:

dispatcher.dispatch( { type: 'ACTION_TYPE', data: { allthe: data} );

simflux:

dispatcher.dispatch('ACTION_TYPE', arg1, arg2, ... );

register, waitFor

Flux:

var todoStore = {
  handleAllActions: function(payload) {
    switch(payload.type) {
      case 'addTodo':
        dispatcher.waitFor([anotherStore.dispatcherToken]);
        ...
        break;
    }
  }
};

todoStore.dispatcherToken = dispatcher.register(todoStore.handleAllActions);

simflux:

var todoStore = {
  addTodo: function(todo) {
    dispatcher.waitFor([anotherStore])
    ...
  }
}

dispatcher.registerStore(todoStore);

access the flux dispatcher

Occasionally, you might want the extra power that Facebook's dispatcher gives you, in which case you can access the instance of the Facebook dispatcher that simflux uses internally via: dispatcher.fluxDispatcher

For example, if you want a store to handle any action that begins with add:

var dispatcher = new simflux.Dispatcher();

var appStore = {
  handleActions: function(payload) {
    var action = payload.action,
        args = payload.args;
    
    if (action.indexOf('add') === 0) {
        // do something with args
    }
  }
}

// register appStore.handleActions with Flux
dispatcher.fluxDispatcher.register(appStore.handleActions);

demo

angular-simflux-experiment: Flux in angularjs

requirements

simflux's People

Contributors

cesarp avatar gbirman-iseatz avatar gilbox avatar

Watchers

 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.