store-prototype

1.1.1 • Public • Published

Store Prototype

Simple class for creating event-driven Data Stores.

Install from npm with npm install --save store-prototype and use as per the example below.

See this gist for a more complete usage example.

Example:

var Store = require('store-prototype');

var MyStore = new Store();
var _things = {};

MyStore.extend({

    getThing: function(key) {
        return _things[key];
    },

    addThing: function(key, data) {
        _things[key] = data;
        this.notifyChange();
    },

    removeThing: function(key) {
        delete _things[key];
        this.notifyChange();
    }

});

MyStore.addChangeListener(function() {
    console.log('Things changed!');
});

Named changes

You can provide a key to addChangeListener and notifyChange to get a little bit more granular control over when change listeners are called.

MyStore.addChangeListener('key', function() {
    console.log('things changed because key!');
});
MyStore.notifyChange(); // ...
MyStore.notifyChange('key'); // things changed because key!

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.1
    118
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.1
    118
  • 1.1.0
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i store-prototype

Weekly Downloads

101

Version

1.1.1

License

MIT

Last publish

Collaborators

  • jedwatson