dwflux

0.0.8 • Public • Published

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
});

Dependencies (3)

Dev Dependencies (1)

Package Sidebar

Install

npm i dwflux

Weekly Downloads

1

Version

0.0.8

License

ISC

Last publish

Collaborators

  • dawee