1.1.0 • Published 7 years ago

mobx-keys-store v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

mobx-keys-store

Build Status Dependency Status devDependency Status

Installation

npm install mobx-keys-store

Usage

import KeysStore from 'mobx-keys-store';

const initialState = {};
const store = new KeysStore(initialState);

/*
 * Observe the store and its properties
 */

store.setItem('foo', 1);
store.increaseItem('foo');

Documentation

Constructor

The constructor can receive an object with initial keys.

Store methods

setItem(name, value)

setItem adds a new or updates an existing property.

removeItem(name)

removeItem removes a property from the store.

increaseItem(name, amount=1)

increaseItem will increase the value of the selected property.

decreaseItem(name, amount=1)

decreaseItem will decrease the value of the selected property

Note

If you try to observe a property which doesn't yet exist, you might not be notified once the property is added. That's why it might be best to add the property to the initial store values.

License

The MIT License

npm.io © 2016 Infinum Inc.