This package has been deprecated

Author message:

this package is deprecated

donburi-model

0.0.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i donburi-model

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators

  • kimagure