node package manager

dwflux

dawee's Flux

Yet another Flux lib based on facebook Emitter/Dispatcher.

Installation

npm install dwflux

Usage

Create an Action

const Action = require('dwflux/action');
 
const clickOnStuff = Action.create((evt, done) => {
  done(null, {
    x: evt.nativeEvent.screenX,
    y: evt.nativeEvent.screenY
  });
});

Trigger an Action

  onMouseClick(evt) {
    clickOnStuff(evt);
  }

Create a Store

const Store = require('dwflux/store');
 
class SelectionStore extends Store {
  
  constructor() {
    super();
    this.register(clickOnStuff, this.selectStuff);
  }
 
  selectStuff(opts) {
    this.selection = {x: opts.x, y: opts.y}
    this.emit('change');
  }
}

Listen to Store changes

const selectionStore = new SelectionStore();
 
selectionStore.on('change', function () {
  // Update your view/component here 
});