# @maexsoftware/datastore

> Immutable datastore objects

Latest version **1.2.4** (published 2016-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @maexsoftware/datastore
pnpm add @maexsoftware/datastore
yarn add @maexsoftware/datastore
bun add @maexsoftware/datastore
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.4 |
| Published | 2016-04-30 |
| First published | 2016-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Maex Software |
| Maintainers | maexsoftware |

## Links

- npm: https://www.npmjs.com/package/@maexsoftware/datastore
- Repository: https://github.com/maexsoftware/datastore
- Issues: https://github.com/maexsoftware/datastore/issues
- npm.io page: https://npm.io/package/@maexsoftware/datastore

## Dependencies (1)

- [node-uuid](https://npm.io/package/node-uuid.md) ^1.4.7

## Recent versions

- 1.2.4 (latest) — 2016-04-30
- 1.2.3 — 2016-04-30
- 1.2.2 — 2016-04-30
- 1.2.1 — 2016-04-30
- 1.2.0 — 2016-04-30
- 1.1.0 — 2016-04-30
- 1.0.1 — 2016-04-30
- 1.0.0 — 2016-04-30

## README

# Datastore

[![Build Status](https://travis-ci.org/maexsoftware/datastore.svg?branch=master)](https://travis-ci.org/maexsoftware/datastore)
[![npm version](https://badge.fury.io/js/%40maexsoftware%2Fdatastore.svg)](https://badge.fury.io/js/%40maexsoftware%2Fdatastore)
[![Coverage Status](https://coveralls.io/repos/github/maexsoftware/datastore/badge.svg?branch=master)](https://coveralls.io/github/maexsoftware/datastore?branch=master)

## Installing

```sh
$ npm install --save @maexsoftware/datastore
```

## Store

### Usage

```js
// Import
const { Store } = require('@maexsoftware/datastore');

// Initialize store
const store = new Store('testStore', 0);

// Add modifier functions to store
store.modifier('increment', (state, value) => state + value);
store.modifier('decrement', (state, value) => state - value);

// Call modifier functions to create modifications to the store state
store.modify.increment(10);
store.modify.decrement(5);

// Calculate new state value
store.state(); // => 5

// The base state does not change
store.baseState; // => 0

// Unless a commit has been made
store.commit();
store.baseState; // => 5

// Stores also have events
store.subscribe('update', function updateListener (modification) {
  console.log('update ran with:', modification);
});

// This will publish an 'update' event
// console will log:
// 'update ran with: { type: increment, value: 100 }'
store.modify.increment(100);

// Events also publish 'updated' events when commits are performed
// console will log:
// 'updated with new state: 105'
const subscription = store.subscribe('updated', function updatedListener (state) {
  console.log('updated with new state:', state);
});

store.commit();

// And of course you can unsubscribe the listener at any point
subscription.unsubscribe();
```

---
_Source: https://npm.io/package/@maexsoftware/datastore · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
