<commit_before># GeneralStore (for Flux) [![Build Status](https://travis-ci.org/HubSpot/general-store.svg)](https://travis-ci.org/HubSpot/general-store)


![general-store](https://git.hubteam.com/github-enterprise-assets/0000/0376/0000/7618/b4cf46ea-a7cb-11e4-86f3-fe5c5c53d10e.jpg)

**This is alpha software. It's going to change.**

GeneralStore aims to get at the essence of a [Flux](http://facebook.github.io/flux/) store without falling into an overly prescriptive data model. A store is an observable reference to a value, with an explicit set of mutations that are triggered by messages from an event emitter.

In other words a store:

1. encapsulates a value (of *any kind*)
2. allows subscribers to read its value
3. updates its value in response to specific messages from the Dispatcher
4. notifies subscribers when its value changes

Other features, like immutability, data fetching, undo, etc., should be implementation details of their individual stores. We also didn’t want to write switch statements anymore… JavaScript switch statements are terrifying.

# Create a store

GeneralStore uses functions to encapsulate private data.

```javascript
var dispatcher = new Flux.Dispatcher();
function defineUserStore() {
  // data is stored privately inside the store module's closure
  var users = {
    123: {
      id: 123,
      name: 'Mary'
    }
  };

  return GeneralStore.define()
    // the store's getter should return the public subset of its data
    .defineGet(function() {<commit_msg>install instructions in the readme<commit_after># GeneralStore (for Flux) [![Build Status](https://travis-ci.org/HubSpot/general-store.svg)](https://travis-ci.org/HubSpot/general-store)


![general-store](https://git.hubteam.com/github-enterprise-assets/0000/0376/0000/7618/b4cf46ea-a7cb-11e4-86f3-fe5c5c53d10e.jpg)

**This is alpha software. It's going to change.**

GeneralStore aims to get at the essence of a [Flux](http://facebook.github.io/flux/) store without falling into an overly prescriptive data model. A store is an observable reference to a value, with an explicit set of mutations that are triggered by messages from an event emitter.

In other words a store:

1. encapsulates a value (of *any kind*)
2. allows subscribers to read its value
3. updates its value in response to specific messages from the Dispatcher
4. notifies subscribers when its value changes

Other features, like immutability, data fetching, undo, etc., should be implementation details of their individual stores. We also didn’t want to write switch statements anymore… JavaScript switch statements are terrifying.

## Install

```
# for node, browserify, etc
npm install general-store

# for bower
bower install general-store
```

## Create a store

GeneralStore uses functions to encapsulate private data.

```javascript
var dispatcher = new Flux.Dispatcher();
function defineUserStore() {
  // data is stored privately inside the store module's closure
  var users = {
    123: {
      id: 123,
      name: 'Mary'
    }
  };

  return GeneralStore.define()
    // the store's getter should return the public subset of its data
    .defineGet(function() {
{'fraction_non_alphanumeric': 0.09047619047619047, 'fraction_numerical': 0.02666666666666667, 'mean_word_length': 4.216887417218543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5117255', 'n_tokens_mistral': 964, 'n_tokens_neox': 870, 'n_words': 363}