statebus 7.0.15 → 7.0.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statebus",
3
- "version": "7.0.15",
3
+ "version": "7.0.16",
4
4
  "description": "Synchronize state.",
5
5
  "main": "statebus.js",
6
6
  "scripts": {
package/server-library.js CHANGED
@@ -233,10 +233,13 @@ function import_server (bus, make_statebus, options)
233
233
  patch.range + ' = ' + patch.content
234
234
  )
235
235
  var cbus = bus.bus_for_http_client(req, res)
236
- cbus.set(req.url.substr(1), {patch: statebus_patches})
237
- res.statusCode = 200
238
- res.end
239
- console.log('We just processed a patch!')
236
+ var key = req.url.substr(1)
237
+ cbus.get_once(key, (obj) => {
238
+ cbus.set(key, {patch: statebus_patches})
239
+ res.statusCode = 200
240
+ res.end
241
+ console.log('We just processed a patch!')
242
+ })
240
243
  })
241
244
  } else {
242
245
  // Otherwise, we assume the body is content-type: json
@@ -2547,7 +2550,7 @@ function free_the_cors (req, res, next) {
2547
2550
  var free_the_cors = {
2548
2551
  "Access-Control-Allow-Origin": "*",
2549
2552
  "Access-Control-Allow-Methods": "OPTIONS, HEAD, GET, PUT, DELETE, UNSUBSCRIBE",
2550
- "Access-Control-Allow-Headers": "subscribe, peer, version, parents, merge-type, content-type, patches, cache-control, put-order"
2553
+ "Access-Control-Allow-Headers": "subscribe, peer, version, parents, merge-type, content-type, content-range, patches, cache-control, put-order"
2551
2554
  }
2552
2555
  Object.entries(free_the_cors).forEach(x => res.setHeader(x[0], x[1]))
2553
2556
  if (req.method === 'OPTIONS') {
package/statebus.js CHANGED
@@ -102,15 +102,15 @@
102
102
  if (typeof obj === 'string' && t && t.patch) {
103
103
  if (typeof t.patch == 'string') t.patch = [t.patch]
104
104
  // Apply the patch locally
105
+ var key = obj,
106
+ obj = bus.cache[key]
107
+
105
108
  console.log('set: applying the patch!', {
106
- key: obj,
107
- val: bus.cache[obj],
109
+ key: key,
110
+ obj: obj,
108
111
  patch: t.patch[0]
109
112
  })
110
- obj = {
111
- key: obj,
112
- val: apply_patch((bus.cache[obj] && bus.cache[obj].val), t.patch[0])
113
- }
113
+ obj.val = apply_patch(obj.val, t.patch[0])
114
114
  }
115
115
 
116
116
  if (!('key' in obj) || typeof obj.key !== 'string') {