statebus 6.1.16 → 6.1.17

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.js CHANGED
@@ -62,7 +62,7 @@
62
62
  var has_prefix = new RegExp('^' + preprefix)
63
63
  var is_absolute = /^https?:\/\//
64
64
  var client_fetched_keys = new bus.Set()
65
- if (url[url.length-1]=='/') url = url.substr(0,url.length-1)
65
+ //if (url[url.length-1]=='/') url = url.substr(0,url.length-1)
66
66
  function add_prefix (key) {
67
67
  return is_absolute.test(key) ? key : preprefix + key }
68
68
  function rem_prefix (key) {
@@ -73,7 +73,6 @@
73
73
  return bus.translate_keys(bus.clone(obj), rem_prefix) }
74
74
 
75
75
  bus(prefix).to_save = function (obj, t) {
76
- console.log('saving', prefix, obj)
77
76
  bus.save.fire(obj)
78
77
 
79
78
  // var x = {save: obj}
@@ -82,9 +81,10 @@
82
81
  // if (t.patch) x.patch = t.patch
83
82
  // if (t.patch) x.save = rem_prefix(x.save.key)
84
83
 
85
- braid_fetch(url + obj.key,
84
+ braid_fetch(url + rem_prefix(obj.key),
86
85
  {
87
86
  method: 'put',
87
+ 'content-type': 'application/json',
88
88
  body: JSON.stringify(obj.val)
89
89
  })
90
90
  }
@@ -94,7 +94,8 @@
94
94
  braid_fetch(url + rem_prefix(key),
95
95
  {
96
96
  method: 'get',
97
- subscribe: true
97
+ subscribe: true,
98
+ headers: {accept: 'application/json'}
98
99
  }
99
100
  ).andThen( x => {
100
101
  t.return({
@@ -439,7 +440,7 @@
439
440
  make_client_statebus_maker()
440
441
  window.bus = window.statebus()
441
442
  bus.label = 'bus'
442
- if (clientjs_option('braid_mode_test'))
443
+ if (clientjs_option('braid_mode'))
443
444
  bus.state = bus.braid_proxy()
444
445
  else
445
446
  window.sb = bus.sb
@@ -450,9 +451,13 @@
450
451
  improve_react()
451
452
  window.ignore_flashbacks = false
452
453
  if (statebus_server !== 'none') {
453
- bus.net_mount ('/*', statebus_server)
454
- if (clientjs_option('braid_mode_test'))
455
- braid_http_mount ('http/*', statebus_server)
454
+ if (clientjs_option('braid_mode')) {
455
+ console.log('We socket-free!')
456
+ braid_http_mount ('/*', statebus_server)
457
+ } else {
458
+ bus.net_mount ('/*', statebus_server)
459
+ console.log('We going websocket!')
460
+ }
456
461
  }
457
462
 
458
463
  if (window.statebus_backdoor) {
@@ -462,7 +467,7 @@
462
467
  bus.net_automount()
463
468
 
464
469
  // This /new/* code is deprecated
465
- if (!clientjs_option('braid_mode_test')) {
470
+ if (!clientjs_option('braid_mode')) {
466
471
  bus('/new/*').to_save = function (o) {
467
472
  if (o.key.split('/').length > 3) return
468
473
 
package/extras/tests.js CHANGED
@@ -872,7 +872,7 @@ test(function proxies2 (done) {
872
872
  })
873
873
 
874
874
  test(function braid_proxies (done) {
875
- var bus = require('../statebus').serve({braid_mode_test: true,
875
+ var bus = require('../statebus').serve({braid_mode: true,
876
876
  file_store: false})
877
877
  var state = bus.state
878
878
 
@@ -896,8 +896,8 @@ test(function braid_proxies (done) {
896
896
  log('array:', state.array)
897
897
  log('bar:', state.bar)
898
898
  assert(state.bar.a[1] !== 2,
899
- "Array ref linked.\n\t"
900
- + JSON.stringify(bus.cache.bar) + '\n\t'
899
+ "Array ref linked.\n\tbar: "
900
+ + JSON.stringify(bus.cache.bar) + '\n\tarray: '
901
901
  + JSON.stringify(bus.cache.array))
902
902
 
903
903
  state.undefining = undefined
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statebus",
3
- "version": "6.1.16",
3
+ "version": "6.1.17",
4
4
  "description": "Synchronize state.",
5
5
  "main": "statebus.js",
6
6
  "scripts": {
package/server.js CHANGED
@@ -106,8 +106,10 @@ function import_server (bus, options)
106
106
  bus.sync_files(x.state_path, x.fs_path)
107
107
  })
108
108
 
109
- // User will put his routes in here
110
- bus.express.use('/', bus.http)
109
+ bus.express.use((req, res, next) => {
110
+ console.log('server.js:', req.method, req.url)
111
+ next()
112
+ })
111
113
 
112
114
  // Free the CORS for Braid requests!
113
115
  bus.express.use((req, res, next) => {
@@ -122,6 +124,9 @@ function import_server (bus, options)
122
124
  next()
123
125
  })
124
126
 
127
+ // User will put his routes in here
128
+ bus.express.use(bus.http)
129
+
125
130
  // Connect bus to the HTTP server
126
131
  bus.express.use(bus.http_handlers)
127
132
 
@@ -175,7 +180,7 @@ function import_server (bus, options)
175
180
 
176
181
  initialize_braid_http: function () {
177
182
  // Set up default linked json converters
178
- if (bus.options.braid_mode_test) {
183
+ if (bus.options.braid_mode) {
179
184
  bus.to_http_body = (o) => JSON.stringify(o.val)
180
185
  bus.state = bus.braid_proxy()
181
186
  } else
@@ -219,16 +224,17 @@ function import_server (bus, options)
219
224
  cbus.fetch(key, cb = (o) => {
220
225
  var body = bus.to_http_body(o)
221
226
 
222
- // Return 404 if the value is undefined
223
- if (!body) {
224
- console.log('no body! time to 404')
225
- res.statusCode = 404
226
- res.end()
227
- }
227
+ // // Return 404 if the value is undefined
228
+ // if (!body) {
229
+ // console.log('no body! time to 404')
230
+ // res.statusCode = 404
231
+ // res.end()
232
+ // }
228
233
 
229
234
  // Or if we're braid, send via subscription
230
- else if (braidify)
231
- res.sendVersion({body})
235
+ // else
236
+ if (braidify)
237
+ res.sendVersion({body: body || 'null'})
232
238
 
233
239
  // Or just return the current version
234
240
  else
@@ -2387,11 +2393,14 @@ function import_server (bus, options)
2387
2393
  serve_clientjs: function serve_clientjs (path) {
2388
2394
  path = path || 'client.js'
2389
2395
  bus.http.get('/' + path, (req, res) => {
2390
- res.send(
2396
+ var files =
2391
2397
  ['extras/coffee.js', 'extras/sockjs.js', 'extras/react.js',
2392
- 'statebus.js', 'client.js']
2393
- .map((f) => fs.readFileSync('node_modules/statebus/' + f))
2394
- .join(';\n'))
2398
+ 'statebus.js', 'client.js'].map((f) => fs.readFileSync('node_modules/statebus/' + f))
2399
+ if (bus.options.braid_mode)
2400
+ files.unshift(fs.readFileSync(
2401
+ 'node_modules/braidify/braidify-client.js'
2402
+ ))
2403
+ res.send(files.join(';\n'))
2395
2404
  })
2396
2405
  },
2397
2406
 
package/statebus.js CHANGED
@@ -1552,6 +1552,8 @@
1552
1552
  else if (x[symbols.is_braid_proxy])
1553
1553
  return ['span', {style: 'background-color: #fffbe5; padding: 3px;'},
1554
1554
  JSON.stringify(x)]
1555
+ // For function proxies:
1556
+ // JSON.stringify(x(), null, 2)]
1555
1557
  },
1556
1558
  hasBody: function (x) {return false}
1557
1559
  }]
@@ -1585,6 +1587,15 @@
1585
1587
  return item_proxy(new_base, new_base.val)
1586
1588
  }
1587
1589
 
1590
+
1591
+ // For function proxies:
1592
+ //
1593
+ // // Javascript won't let us function call a proxy unless the
1594
+ // // "target" is a function. So we make a dummy target, and
1595
+ // // don't use it.
1596
+ // var dummy = function () {}
1597
+
1598
+
1588
1599
  return new Proxy(o, {
1589
1600
  get: function get(o, k) {
1590
1601
  if (k === 'inspect' || k === 'valueOf')
@@ -1606,20 +1617,24 @@
1606
1617
  },
1607
1618
  deleteProperty: function del (o, k) {
1608
1619
  delete o[proxied_2_keyed(k)]
1609
- },
1610
- apply: function apply (o, This, args) {
1611
- return o
1612
1620
  }
1621
+ // For function proxies:
1622
+ //
1623
+ // apply: function apply (o, This, args) {
1624
+ // return translate_fields(o, keyed_2_proxied)
1625
+ // }
1613
1626
  })}
1614
1627
 
1615
1628
 
1629
+ // For function proxies:
1630
+ // var dummy = function () {}
1631
+
1616
1632
  // The top-level Proxy object holds HTTP resources
1617
1633
  return new Proxy(cache, {
1618
1634
  get: function get(o, k) {
1619
1635
  if (k === 'inspect' || k === 'valueOf' || typeof k === 'symbol')
1620
1636
  return undefined
1621
- if (k in bogus_keys)
1622
- return o[k]
1637
+ bogus_check(k)
1623
1638
  var base = bus.fetch(k)
1624
1639
  return item_proxy(base, base.val)
1625
1640
  },
@@ -1630,7 +1645,11 @@
1630
1645
  },
1631
1646
  deleteProperty: function del (o, k) {
1632
1647
  bus.delete(proxied_2_keyed(k))
1633
- }
1648
+ },
1649
+ // For function proxies:
1650
+ // apply: function apply (o, This, args) {
1651
+ // return 'fluffy'
1652
+ // }
1634
1653
  })
1635
1654
  }
1636
1655
 
@@ -1640,8 +1659,8 @@
1640
1659
  return result
1641
1660
  }
1642
1661
 
1643
- if ((nodejs && bus.options && bus.options.braid_mode_test)
1644
- || (!nodejs && window.Proxy && clientjs_option('braid_mode_test')))
1662
+ if ((nodejs && bus.options && bus.options.braid_mode)
1663
+ || (!nodejs && window.Proxy && clientjs_option('braid_mode')))
1645
1664
  state = braid_proxy()
1646
1665
 
1647
1666