Jada
Jada is a simple, lightweight library for storing data. It does not update localStorage, nor does it provide hooks for syncing data to a server. It simply gets and sets data, and provides hooks for listening to when data has been set both before and after.
Size
Jada is 2.6kb in size when minified.
Example
var datastore = Jada; { var currentValue = datastore; console; console console; console; console; console; console;} // Fires twice,// once before setting 'my-key' and// once before setting 'my-other-key'// // This callback will fire before any key is set.datastore; // Fires twice,// once after setting 'my-key' and// once after setting 'my-other-key'// // This callback will fire after any key is set.datastore; // Fires once,// once before setting 'my-key'// // This callback will fire once before the specified key is set.datastore; // Fires once,// once after setting 'my-key'// // This callback will fire once after the specified key is set.datastore; // Sets 'my-key' to the value 'Hello, world!'datastore; // Sets 'my-other-key' to the value 'Goodbye, Bob!'datastore; // This will log the value 'Hello, World!'// for the key 'my-key'.console; // This will log the value 'Goodbye, Bob!'// for the key 'my-other-key'.console;
The above will output the following log:
Before All
=============
Key: my-key
Current Value: undefined
Old Value: undefined
New Value: Hello, World!
Before my-key
=============
Key: my-key
Current Value: undefined
Old Value: undefined
New Value: Hello, World!
After All
=============
Key: my-key
Current Value: Hello, World!
Old Value: undefined
New Value: Hello, World!
After my-key
=============
Key: my-key
Current Value: Hello, World!
Old Value: undefined
New Value: Hello, World!
Before All
=============
Key: my-other-key
Current Value: undefined
Old Value: undefined
New Value: Goodbye, Bob!
After All
=============
Key: my-other-key
Current Value: Goodbye, Bob!
Old Value: undefined
New Value: Goodbye, Bob!
Hello, World!
Goodbye, Bob!
API
The Jada API consists of a very simple set of verbs for manipulating and listening to the data within your store.
Jada Singleton
create([data])
Create is the sole method on the Jada
object. It is used to create a datastore instance.
Usage
Creating a datastore with no predefined values.
var datastore = Jada;
Creating a datastore with predefined values.
var datastore = Jada; console; // outputs 'Hello, World!'
Datastore Instance
get(key)
Get the current value associated with the specified key.
Usage
var datastore = Jada; var val = datastore; console; // outputs [ 1, 2, 3 ]
set(key, value)
Sets a key to the specified value.
Usage
var datastore = Jada; datastore; var val = datastore; console; // outputs { name: 'Jesse' }
remove(key)
Removes both the key and value from the datastore.
Usage
var datastore = Jada; console; // outputs 'Jesse' datastore; console; // outputs undefined
dump()
Dumps the entire contents of the data store as a javascript object.
Usage
var datastore = Jada; console; // outputs { name: 'Jesse' }
keys()
Returns an array of all the keys within the datastore.
Usage
var datastore = Jada; console; // outputs [ 'name', 'height' ]
clear()
Clears all the data out of the datastore.
Usage
var datastore = Jada; console; // outputs { name: 'Jesse' } datastoreclear; console; // outputs {}
before([key], callback)
The before listener fires before a key is set. The key is optional, if only a callback is provided, then the callback will fire before all keys are set.
Usage
var datastore = Jada; // Only fires when 'name' is set.datastore; // Fires before any key is setdatastore; datastore; // outputs true // outputs 'name' datastore; // outputs 'height'
after([key], callback)
The after listener fires after a key is set. The key is optional, if only a callback is provided, then the callback will fire after all keys are set.
Usage
var datastore = Jada; // Only fires after 'name' is set.datastore; // Fires after any key is setdatastore; datastore; // outputs true // outputs 'name' datastore; // outputs 'height'