Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Associate arbitrary data with a context (a simple plain JavaScript object)
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.npmignore
LICENSE
README.md
package.json
test.js

README.md

SimpleContext

Associate arbitrary data with a context (a simple plain JavaScript object).

Installation

Via npm on Node:

npm install simplecontext

Usage

Reference in your program:

var sc = require('simplecontext');

Create an space to store the data and contexts:

var space = sc.createSpace();

Add an item to a context:

space.assert('John', { country: 'UK' });
space.assert('Mary', { country: 'UK' });
space.assert('Ann', { country: 'UK', category: 'Beverages' });

A context is a simple JavaScript object, like { country: 'UK' } or { country: 'UK', category: 'Dairy' }. Internally, { country: 'UK', category: 'Dairy' } and { category: 'Dairy', country: 'UK' } are the same context.

Retrieve the items associated to a context:

var result = space.retrieve({ country: 'UK' }); // [ 'John', 'Mary' ]
var result = space.retrieve({ country: 'Japan' }); // [ ]
var result = space.retrieve({ country: 'UK', category: 'Beverages' }); // [ 'John', 'Mary', 'Ann' ]

Notice the use of inheritance in the last retrieve.

Retract an item from a context:

space.retract('John', { country: 'UK' });

Remove a context:

space.remove({ category: 'Beverages', country: 'UK' });

Development

git clone git://github.com/ajlopez/SimpleContext.git
cd SimpleContext
npm install
npm test

Samples

TBD

References

TBD

Contribution

Feel free to file issues and submit pull requests — contributions are welcome<

If you submit a pull request, please be sure to add or update corresponding test cases, and ensure that npm test continues to pass.

Something went wrong with that request. Please try again.