Skip to content

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

License

Notifications You must be signed in to change notification settings

ajlopez/SimpleContext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published