object-db
v2.0.0
Published
Get, Set, and Subscribe, across browser windows & tabs. Just 2kb.
Downloads
11
Maintainers
Readme
object-db
In browser JavaScript object storage. Get, Set, and Subscribe. Works across browser tabs and windows. Just 2kb.
Installation:
Simply install using npm.
npm install --save object-db
Usage
// Require ObjectDB
const ObjectDB = require('object-db');
// Init the DB, you can pass an object to init as a template (optional).
let myDB = new ObjectDB('test_db').init({ sweet: true });
// You can also subscribe to the DB.
myDB.subscribe((data) => {
console.log(data);
});
// Await a specific item
myDB.await('example', example => {
console.log('your await happened', example);
});
// Get all database contents.
console.log(
myDB.get()
);
// Get database item.
myDB.get('tested');
/// Remove a database item.
myDB.remove('tested');
// Purge and re-init the database.
myDB.purge().init();
// Triggers await, and subscribe.
myDB.set({
example: 'boom'
});
setTimeout(function() {
// Triggers await, and subscribe again.
myDB.set({
example: 'boom'
});
}, 1500);