statebus 7.0.17 → 7.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client-library.js +12 -4
- package/package.json +1 -1
- package/statebus.js +33 -5
package/client-library.js
CHANGED
|
@@ -201,6 +201,7 @@
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
// Else, reconnect!
|
|
204
|
+
console.log('Reconnecting due to', e)
|
|
204
205
|
setTimeout(() => subscribe(key, t),
|
|
205
206
|
reconnect_attempts > 0 ? 5000 : 1500)
|
|
206
207
|
subscriptions[key].status = 'reconnecting'
|
|
@@ -232,10 +233,17 @@
|
|
|
232
233
|
}
|
|
233
234
|
|
|
234
235
|
// Return the update
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
if (new_version.body)
|
|
237
|
+
// As a snapshot body
|
|
238
|
+
t.return({
|
|
239
|
+
key: key,
|
|
240
|
+
val: add_prefixes(JSON.parse(new_version.body))
|
|
241
|
+
})
|
|
242
|
+
else if (new_version.patches)
|
|
243
|
+
// As a patch
|
|
244
|
+
bus.set.fire(key, {patch: new_version.patches.map(
|
|
245
|
+
patch => patch.range + ' = ' + patch.content
|
|
246
|
+
)})
|
|
239
247
|
},
|
|
240
248
|
reconnect
|
|
241
249
|
)).catch(reconnect)
|
package/package.json
CHANGED
package/statebus.js
CHANGED
|
@@ -186,6 +186,26 @@
|
|
|
186
186
|
|| executing_funk && executing_funk.latest_reaction_at
|
|
187
187
|
|| new_version()
|
|
188
188
|
|
|
189
|
+
// Handle patches. We receive them as:
|
|
190
|
+
//
|
|
191
|
+
// set.fire("foo", {patch: ['.foo.bar = "blah"]})
|
|
192
|
+
//
|
|
193
|
+
// Note the `obj` will actually be a string, set to the key in this case.
|
|
194
|
+
//
|
|
195
|
+
if (typeof obj === 'string' && t && t.patch) {
|
|
196
|
+
if (typeof t.patch == 'string') t.patch = [t.patch]
|
|
197
|
+
// Apply the patch locally
|
|
198
|
+
var key = obj,
|
|
199
|
+
obj = bus.cache[key]
|
|
200
|
+
|
|
201
|
+
console.log('set.fire: applying the patch!', {
|
|
202
|
+
key: key,
|
|
203
|
+
obj: obj,
|
|
204
|
+
patch: t.patch[0]
|
|
205
|
+
})
|
|
206
|
+
obj.val = apply_patch(obj.val, t.patch[0])
|
|
207
|
+
}
|
|
208
|
+
|
|
189
209
|
// Print a statelog entry
|
|
190
210
|
if (obj.key && honking_at(obj.key)) {
|
|
191
211
|
// Warning: Changes to *nested* objects will *not* be printed out!
|
|
@@ -1771,7 +1791,7 @@
|
|
|
1771
1791
|
: parseInt(numstr)
|
|
1772
1792
|
}
|
|
1773
1793
|
|
|
1774
|
-
console.log('Getting path', path, 'in obj', obj)
|
|
1794
|
+
console.log('Getting path', JSON.stringify(path), 'in obj', obj)
|
|
1775
1795
|
|
|
1776
1796
|
while (true) {
|
|
1777
1797
|
var match = path_segment.exec(path),
|
|
@@ -1790,11 +1810,19 @@
|
|
|
1790
1810
|
|
|
1791
1811
|
// If it's the final item, set it
|
|
1792
1812
|
if (path.length == subpath.length) {
|
|
1793
|
-
if (
|
|
1794
|
-
|
|
1813
|
+
if (!subpath) return new_stuff
|
|
1814
|
+
else if (field) // Object
|
|
1815
|
+
if (new_stuff === undefined)
|
|
1816
|
+
delete curr_obj[field] // - Delete a field in object
|
|
1817
|
+
else
|
|
1818
|
+
curr_obj[field] = new_stuff // - Set a field in object
|
|
1819
|
+
|
|
1795
1820
|
else if (typeof curr_obj == 'string') { // String
|
|
1796
|
-
console.assert(typeof new_stuff
|
|
1797
|
-
if (!slice_start) {
|
|
1821
|
+
console.assert(typeof new_stuff === 'string')
|
|
1822
|
+
if (!slice_start) {
|
|
1823
|
+
slice_start = slice_end
|
|
1824
|
+
slice_end = slice_end + 1
|
|
1825
|
+
}
|
|
1798
1826
|
if (last_obj) {
|
|
1799
1827
|
var s = last_obj[last_field]
|
|
1800
1828
|
last_obj[last_field] = (s.slice(0, slice_start)
|