1.0.0 • Published 9 years ago
duet-localforage v1.0.0
duet-localforage
Use localForage with duet by selectively reading and writing asynchronously across threads when IndexedDB is not available to the worker, otherwise use it directly.
$ npm install duet-localforageUsage
var duet = require('duet');
var channel = require('duet-localforage/channel');
var localforage = require('duet-localforage');
var logger = console.log.bind(console);
duet([channel], function () {
/* A: Promises */
localforage.clear().then(logger);
// >
localforage.length().then(logger);
// > 0
localforage.setItem('foo', 'bar').then(logger);
// > 'bar'
localforage.key(0).then(logger);
// > 'foo'
localforage.keys().then(logger);
// > ['foo']
localforage.getItem('foo').then(logger);
// > 'bar'
localforage.iterator(logger).then(logger);
// > 'bar', 'foo', 1
// >
localforage.removeItem('foo').then(logger);
// >
/* B: Callbacks */
localforage.clear(logger);
// > null
localforage.length(logger);
// > null, 0
localforage.setItem('foo', 'bar', logger);
// > null, 'bar'
localforage.key(0, logger);
// > null, 'foo'
localforage.keys(logger);
// > null, ['foo']
localforage.getItem('foo', logger);
// > null, 'bar'
localforage.iterator(logger, logger);
// > 'bar', 'foo', 1
// > null
localforage.removeItem('foo', logger);
// > null
});API
Everything is as you would expect on the localForage's callback and Promise-based async APIs.
Supported types
duet-localforage can safely store the following types of data:
- All† primitives
ObjectBooleanobjectStringobjectBlobArrayArrayBufferInt8ArrayUint8ArrayUint8ClampedArrayInt16ArrayUint16ArrayInt32ArrayUint32ArrayFloat32ArrayFloat64Array
This list is the intersection of the types that localForage can normally store, and the types that can be sent between workers as structured clones.
† Note about primitives: Symbol isn't supported. undefined will be stored and retrieved as null.
1.0.0
9 years ago