0.0.2 • Published 9 years ago

donburi-model v0.0.2

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

Donburi Model Build Status

Made by taking ideas from facebook/flux Dispatcher and the example Store and Action implementations, this module attempts to bring a simple single Model for managing application state.

The idea is to store application in one object, to provide a single source of truth. All handling functions are called by a request method and are run synchronously.

Usage

var getModel = require('donburi-model').getModel;
var Constants = require('./Constants');

function addOne(operand) {
  return operand + 1;
}

var Model = getModel({
  counter: 0
});

Model.register(Constants.ADD_SOMETHING, function () {
  var state = Model.getState();
  // controlled mutation by getting a result from a pure function
  state.counter = addOne(state.counter);
  Model.update();
});
Model.register(Constants.REMOVE_SOMETHING, function () {
  Model.getState().counter -= 1;
  Model.update();
});

module.exports = Model;

Examples

See the tests in modules/__tests__/DonburiModel.js and the example application in examples/clicker.

Demo

See this JSBin for a demo.

References

facebook/flux

0.0.2

9 years ago

0.0.1

9 years ago