1.0.3 • Published 4 years ago

@jacobbubu/merged-model v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

@jacobbubu/merged-model

Build Status Coverage Status npm

A subclass of scuttlebutt-pull/model that supports merged values with same key.

Usage

const a = new MergedModel('A')
const b = new MergedModel('B')

const s1 = a.createStream({ name: 'a->b' })
const s2 = b.createStream({ name: 'b->a' })

a.set('num', 1)
b.set('num', 2)
a.set('foo', { foo: 'one' })
b.set('foo', { bar: 'two' })

s2.on('synced', () => {
  expect(b.toJSON()).toEqual({ num: 2, foo: { foo: 'one', bar: 'two' } })
  done()
})

link(s1, s2)