statebus 6.1.11 → 6.1.12
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 +75 -11
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -57,6 +57,61 @@
|
|
|
57
57
|
return {clientid: me.client}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
function braid_http_mount (prefix, url) {
|
|
61
|
+
var preprefix = prefix.slice(0,-1)
|
|
62
|
+
var has_prefix = new RegExp('^' + preprefix)
|
|
63
|
+
var client_fetched_keys = new bus.Set()
|
|
64
|
+
if (url[url.length-1]=='/') url = url.substr(0,url.length-1)
|
|
65
|
+
function add_prefix (key) {
|
|
66
|
+
return is_absolute.test(key) ? key : preprefix + key }
|
|
67
|
+
function rem_prefix (key) {
|
|
68
|
+
return has_prefix.test(key) ? key.substr(preprefix.length) : key }
|
|
69
|
+
function add_prefixes (obj) {
|
|
70
|
+
return bus.translate_keys(bus.clone(obj), add_prefix) }
|
|
71
|
+
function rem_prefixes (obj) {
|
|
72
|
+
return bus.translate_keys(bus.clone(obj), rem_prefix) }
|
|
73
|
+
|
|
74
|
+
bus(prefix).to_save = function (obj, t) {
|
|
75
|
+
console.log('saving', prefix, obj)
|
|
76
|
+
bus.save.fire(obj)
|
|
77
|
+
|
|
78
|
+
// var x = {save: obj}
|
|
79
|
+
// if (t.version) x.version = t.version
|
|
80
|
+
// if (t.parents) x.parents = t.parents
|
|
81
|
+
// if (t.patch) x.patch = t.patch
|
|
82
|
+
// if (t.patch) x.save = rem_prefix(x.save.key)
|
|
83
|
+
|
|
84
|
+
braid_fetch(url + obj.key,
|
|
85
|
+
{
|
|
86
|
+
method: 'put',
|
|
87
|
+
body: JSON.stringify(obj.val)
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
bus(prefix).to_fetch = function (key, t) {
|
|
92
|
+
try {
|
|
93
|
+
braid_fetch(url + rem_prefix(key),
|
|
94
|
+
{
|
|
95
|
+
method: 'get',
|
|
96
|
+
subscribe: true
|
|
97
|
+
}
|
|
98
|
+
).andThen( x => {
|
|
99
|
+
t.return({
|
|
100
|
+
key,
|
|
101
|
+
val: add_prefixes(JSON.parse(x.body))
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
} catch (e) {
|
|
105
|
+
console.error('Braid-HTTP network error:', e)
|
|
106
|
+
}
|
|
107
|
+
client_fetched_keys.add(key)
|
|
108
|
+
}
|
|
109
|
+
bus(prefix).to_forget = function (key) {
|
|
110
|
+
// send({forget: key}),
|
|
111
|
+
client_fetched_keys.delete(key)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
60
115
|
|
|
61
116
|
// ****************
|
|
62
117
|
// Manipulate Localstorage
|
|
@@ -382,16 +437,22 @@
|
|
|
382
437
|
react_render = React.version >= '0.14.' ? ReactDOM.render : React.render
|
|
383
438
|
make_client_statebus_maker()
|
|
384
439
|
window.bus = window.statebus()
|
|
385
|
-
|
|
386
|
-
|
|
440
|
+
bus.label = 'bus'
|
|
441
|
+
if (clientjs_option('braid_mode_test'))
|
|
442
|
+
bus.state = bus.braid_proxy()
|
|
443
|
+
else
|
|
444
|
+
window.sb = bus.sb
|
|
387
445
|
statebus.widget = React_View
|
|
388
446
|
statebus.create_react_class = React_View
|
|
389
447
|
statebus.createReactClass = React_View
|
|
390
448
|
|
|
391
449
|
improve_react()
|
|
392
450
|
window.ignore_flashbacks = false
|
|
393
|
-
if (statebus_server !== 'none')
|
|
451
|
+
if (statebus_server !== 'none') {
|
|
394
452
|
bus.net_mount ('/*', statebus_server)
|
|
453
|
+
if (clientjs_option('braid_mode_test'))
|
|
454
|
+
braid_http_mount ('http/*', statebus_server)
|
|
455
|
+
}
|
|
395
456
|
|
|
396
457
|
if (window.statebus_backdoor) {
|
|
397
458
|
window.master = statebus()
|
|
@@ -399,16 +460,19 @@
|
|
|
399
460
|
}
|
|
400
461
|
bus.net_automount()
|
|
401
462
|
|
|
402
|
-
//
|
|
403
|
-
|
|
404
|
-
|
|
463
|
+
// This /new/* code is deprecated
|
|
464
|
+
if (!clientjs_option('braid_mode_test')) {
|
|
465
|
+
bus('/new/*').to_save = function (o) {
|
|
466
|
+
if (o.key.split('/').length > 3) return
|
|
405
467
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
468
|
+
var old_key = o.key
|
|
469
|
+
o.key = old_key + '/' + Math.random().toString(36).substring(2,12)
|
|
470
|
+
statebus.cache[o.key] = o
|
|
471
|
+
delete statebus.cache[old_key]
|
|
472
|
+
bus.save(o)
|
|
473
|
+
}
|
|
411
474
|
}
|
|
475
|
+
|
|
412
476
|
load_coffee()
|
|
413
477
|
|
|
414
478
|
statebus.compile_coffee = compile_coffee
|