git ssb

1+

Matt McKegg / mutant



Commit c1883dce4e666e45b62e08d2c4e605130ccb968a

set: partial update on 'set', only emit if new value is different (like struct)

Matt McKegg committed on 11/3/2016, 12:44:18 PM
Parent: 07bf7e400c9cbb4babe9aa90386152ccb2731feb

Files changed

set.jschanged
set.jsView
@@ -76,15 +76,33 @@
7676 }
7777
7878 ProtoSet.prototype.set = function (values) {
7979 var self = this
80- self.sources.length = 0
80 + var changed = false
81 +
8182 if (Array.isArray(values)) {
83 + for (var i = this.sources.length - 1; i >= 0; i -= 1) {
84 + if (!~values.indexOf(this.sources[i])) {
85 + changed = true
86 + self.sources.splice(i, 1)
87 + }
88 + }
8289 values.forEach(function (value) {
83- self.sources.push(value)
90 + if (!~self.sources.indexOf(value)) {
91 + changed = true
92 + self.sources.push(value)
93 + }
8494 })
95 + } else {
96 + if (self.sources.length > 0) {
97 + self.sources.length = 0
98 + changed = true
99 + }
85100 }
86- self.binder.onUpdate()
101 +
102 + if (changed) {
103 + self.binder.onUpdate()
104 + }
87105 }
88106
89107 ProtoSet.prototype.get = function (index) {
90108 return this.sources[index]

Built with git-ssb-web