localstorage-scuttlebutt
replicate localstorage through scuttlebutt.
The same api as scuttlebutt/model but data is saved in the browser using local storage.
Example
var LSSB =var ls = prefix: prefix id: id store: localStoragelslsls
prefix
is the name of this instance. If you are using multiple instances,
or have other data in localStorage
you need to set this. By default,
prefix='_lss'
.
id
should be a unique string that represents the user session.
you should save this in localStorage
(or a cookie).
The same id may be reused across multiple tabs,
but not across different browsers or devices.
store
defaults to localStorage
, but sessionStorage
may also be used.
(store must have length
property and a key()
method.
Replication
replicate with a normal scuttlebutt/model
, across anything that provides a Stream api.
//clientvar reconnect =var LSSB =var ls = id: ID prefix: prefix
//server.jsvar shoe =var Model =var model = SERVER_ID
API
Local
opts represents the identity of the current machine.
It should corrispond to the user session in this browser.
prefix is the name of this object. You may use multiple
localstorage-scuttlebutt
instances in different parts of the same application
by using different prefixes.
var LSSB =var opts = id: id prefix: prefixvar model = opts
createStream()
connect to a remote instance via a duplex stream.
reconnect(function (stream) {
stream.pipe(model.createStream()).pipe(stream)
}).connect('/shoe')
set(key, value)
set a property on an instance.
model
get(key)
get a property on an instance.
model
keys()
get all keys on instance as an array.
model
each(function (value, key) {...})
iterate over all value, key
pairs.
model
value
is first, like in [].forEach
License
MIT