0.2.1 • Published 9 years ago

fluxtown-funk v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 years ago

fluxtown-funk

Syntactic sugar for Flux based React apps

Usage

ES6 is required.

Actions

/**
 * All actions will be prefixed with a lower case
 * version of the given name. (`todo:`, here)
 */
const TodoActions = createActions('Todo', {
  
  /**
   * promised is a helper for creating actions
   * that deal with async stuff. The function must
   * return a an array of two elements: The object passed through the dispatcher initially and a promise.
   *
   * Available as `TodoActions.create('Hello World');`
   * This will send {text: 'Hello World'} through the dispatcher right away, and when the promise completes or fails
   * dispatch createCompleted or completeFailed respectively.
   */
  create: promised(text => [{ text }, TodoService.create(text)]),

  /**
   * Send empty payload of type clearAll through the dispatcher.
   */
  clearAll: true
});

Stores

let _todos = [];
const TodoStore = createStore({
  
  getAll() {
    return _todos;
  },

  areAllCompleted() {
    return !_todos.some(todo => !todo.completed);
  },

  /**
   * Define actions the store will respond to
   * here. A change event will automatically be emitted.
   * This behaviour can be avoided by returning false.
   */
  actions: {
    'todo:create'(action) {
      _todos.push({text: action.text});
    },

    'todo:bar'(action) {
      return false;
    }
  }
});

Dispatcher

You'll probably never need to access this directly, but it can be nice to log everything passing through it for debugging purposes

import {Dispatcher} from 'fluxtown-funk';
Dispatcher.register(console.log.bind(console));

License

MIT

0.2.1

9 years ago

0.2.0

9 years ago

0.1.1

9 years ago