Socket
Book a DemoInstallSign in
Socket

donburi-model

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

donburi-model

Simple model module for JS applications

0.0.2
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 26 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.