scuttleboat

0.0.1 • Public • Published

sailboat upsidedown

Sail the high seas with ScuttleBoat

Like Scuttlebucket, but allows for dynamically adding records later

var ScuttleBoat = require('scuttleboat')
var Model = require('scuttlebutt/model')
 
 
// Define sub-document constructor types
 
opts = {
  constructors: {
    Model: Model,
  },
}
 
 
// Setup ScuttleBoats
 
A = new ScuttleBoat(opts)
B = new ScuttleBoat(opts)
 
var as = A.createStream()
var bs = B.createStream()
 
as.pipe(bs).pipe(as)
 
 
// Dynamically add sub-documents
 
aMeta = A.add('meta', 'Model')
aMeta.set('a',9)
 
 
// Subdocuments are created and synced
 
setTimeout(function(){
 
  console.log( B.get('meta').get('a') ) // => 9
 
}, 200)

API

Add a sub-document to the boat. The sub-document instance will be created automatically. Provide:

  • the key (string)
  • the type from the list of constructors (string)
  • an (optional) argument to instantiate the instance with. Argument must be serializable. Cannot provide more than one initialization argument.
boat.add(key, type, opts)

Get a list of all subdocs

boat.list() //=> {key1: subdoc1, key2: subdoc2, ...}

Clone a scuttleboat instance

boat.clone()

Listen for new subdocs

boat.on('create', function(key, subdoc){ /* ... */ })

Readme

Keywords

none

Package Sidebar

Install

npm i scuttleboat

Weekly Downloads

1

Version

0.0.1

License

BSD-2-Clause

Last publish

Collaborators

  • kumavis