Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kumavis/scuttleboat
:boat: Scuttlebucket with a manifest for dynamic records
https://github.com/kumavis/scuttleboat
Last synced: 3 months ago
JSON representation
:boat: Scuttlebucket with a manifest for dynamic records
- Host: GitHub
- URL: https://github.com/kumavis/scuttleboat
- Owner: kumavis
- Created: 2014-12-08T10:30:05.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-09-08T05:41:46.000Z (over 7 years ago)
- Last Synced: 2024-10-19T03:58:38.757Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-peer-to-peer - scuttleboat
- awesome-peer-to-peer - scuttleboat
README
![sailboat upsidedown](https://cloud.githubusercontent.com/assets/1474978/4873103/2392582a-6202-11e4-9a42-4afc8b988648.png)
### Sail the high seas with ScuttleBoat
Like [Scuttlebucket](https://github.com/dominictarr/scuttlebucket), but allows for dynamically adding records later
```js
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.```js
boat.add(key, type, opts) //=> subdoc
```Query a subdoc
```js
boat.get(key) //=> subdoc
```Get a list of all subdocs
```js
boat.list() //=> {key1: subdoc1, key2: subdoc2, ...}
```Clone a scuttleboat instance
```js
boat.clone()
```Listen for new subdocs
```js
boat.on('create', function(key, subdoc){ /* ... */ })
```This class inherits from [Scuttlebucket](https://github.com/dominictarr/scuttlebucket), see the documentation there for more info.