<commit_before># JSON API Store [![Build Status](https://travis-ci.org/haydn/json-api-store.svg?branch=master)](https://travis-ci.org/haydn/json-api-store)

JSON API Store takes [JSON API](http://jsonapi.org) data and creates plain
JavaScript objects for the resources it describes. It will link-up
relationships automatically and update both sides of reciprocal relationships
when either side is modified.

## Usage

At the moment you need to do your own AJAX requests, but there are plans to add
AJAX methods to create, read, update and destroy resources in the future. For
now you can just push the responses from your own requests to the store:

```javascript

// Create a new store instance.
var store = new Store();

// Define the "categories" type.
store.define("categories", {
  title: Store.attr(),
  products: Store.hasMany({ inverse: "category" })
});

// Define the "products" type.
store.define("products", {
  title: Store.attr(),
  category: Store.hasOne()
});

// Add data - this can just be the response from a GET request to your API.
store.push({
  "data": {
    "type": "products",
    "id": "1",
    "attributes": {
      "title": "Example Book"
    },
    "relationships": {
      "category": {<commit_msg>Update the example in the README.<commit_after># JSON API Store [![Build Status](https://travis-ci.org/haydn/json-api-store.svg?branch=master)](https://travis-ci.org/haydn/json-api-store)

JSON API Store takes [JSON API](http://jsonapi.org) data and creates plain
JavaScript objects for the resources it describes. It will link-up
relationships automatically and update both sides of reciprocal relationships
when either side is modified.

## Usage

At the moment you need to do your own AJAX requests, but there are plans to add
AJAX methods to create, read, update and destroy resources in the future. For
now you can just push the responses from your own requests to the store:

```javascript

// Create a new store instance.
var store = new Store();

// Define the "categories" type.
store.define([ "categories", "category" ], {
  title: Store.attr(),
  products: Store.hasMany()
});

// Define the "products" type.
store.define([ "products", "product" ], {
  title: Store.attr(),
  category: Store.hasOne()
});

// Add data - this can just be the response from a GET request to your API.
store.push({
  "data": {
    "type": "products",
    "id": "1",
    "attributes": {
      "title": "Example Book"
    },
    "relationships": {
      "category": {
{'fraction_non_alphanumeric': 0.12721417069243157, 'fraction_numerical': 0.0008051529790660225, 'mean_word_length': 3.8346303501945527, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '5573829', 'n_tokens_mistral': 733, 'n_tokens_neox': 712, 'n_words': 291}