git ssb

1+

Matt McKegg / mutant



Commit e98a74f353b7212d30146e7700944d65f5422188

struct: add extend option to set

Matt McKegg committed on 2/24/2017, 5:26:51 PM
Parent: e32aa3719b669ed0dd1f7ad2e1b86390c19ae61a

Files changed

struct.jschanged
struct.jsView
@@ -1,14 +1,15 @@
11 var Value = require('./value')
22 var LazyWatcher = require('./lib/lazy-watcher')
33 var isSame = require('./lib/is-same')
4 +var extend = require('xtend')
45
56 module.exports = Struct
67
78 var blackList = {
89 'length': 'Clashes with `Function.prototype.length`.\n',
910 'name': 'Clashes with `Function.prototype.name`\n',
10- 'destroy': '`destroy` is a reserved key of struct\n'
11 + 'set': '`set` is a reserved key of struct\n'
1112 }
1213
1314 function Struct (properties, opts) {
1415 var object = Object.create({})
@@ -43,13 +44,18 @@
4344 object[key] = obs()
4445 observable[key] = obs
4546 })
4647
47- observable.set = function (values) {
48 + observable.set = function (values, opts) {
4849 var lastValue = suspendBroadcast
50 +
4951 suspendBroadcast = true
5052 values = values || {}
5153
54 + if (opts && opts.merge) {
55 + values = extend(object, values)
56 + }
57 +
5258 // update inner observables
5359 keys.forEach(function (key) {
5460 if (observable[key]() !== values[key]) {
5561 observable[key].set(values[key])

Built with git-ssb-web