statebus 7.0.26 → 7.0.27
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/extras/tests.js +6 -2
- package/package.json +1 -1
- package/statebus.js +20 -7
package/extras/tests.js
CHANGED
|
@@ -296,11 +296,15 @@ test(function url_translation (done) {
|
|
|
296
296
|
})
|
|
297
297
|
|
|
298
298
|
test(function proxy_link (done) {
|
|
299
|
-
console.log('lets test')
|
|
300
|
-
|
|
301
299
|
bus.state.link_from = [{link: 'link_to'}]
|
|
302
300
|
bus.state.link_to = 3
|
|
303
301
|
assert(bus.state.link_from[0] !== 3, 'Link got linkified')
|
|
302
|
+
console.log('link_from is', bus.state.link_from)
|
|
303
|
+
var pass = bus.deep_equals(bus.state.link_from, [{link: 'link_to'}])
|
|
304
|
+
console.log('pass is', pass)
|
|
305
|
+
assert(pass, 'Failed proxy link unlinky test')
|
|
306
|
+
|
|
307
|
+
// assert(bus.deep_equals(bus.state.link_from, [{link: 'link_to'}]), 'Link_from looks wrong')
|
|
304
308
|
|
|
305
309
|
done()
|
|
306
310
|
})
|
package/package.json
CHANGED
package/statebus.js
CHANGED
|
@@ -1305,6 +1305,10 @@
|
|
|
1305
1305
|
// get_base: Symbol('get_base')
|
|
1306
1306
|
}
|
|
1307
1307
|
function make_proxy () {
|
|
1308
|
+
// var custom_inspect_symbol = nodejs && require('util').inspect.custom,
|
|
1309
|
+
// custom_inspect = function (depth, options) {
|
|
1310
|
+
// return '3333333333';// util.inspect(bus.unescape_from_nelson(this), options)
|
|
1311
|
+
// }
|
|
1308
1312
|
function item_proxy (base, path, o) {
|
|
1309
1313
|
|
|
1310
1314
|
// Primitives pass through unscathed
|
|
@@ -1336,6 +1340,8 @@
|
|
|
1336
1340
|
get: function get(o, k) {
|
|
1337
1341
|
if (k === 'inspect' || k === 'valueOf')
|
|
1338
1342
|
return undefined
|
|
1343
|
+
// if (custom_inspect && k === custom_inspect)
|
|
1344
|
+
// return custom_inspect
|
|
1339
1345
|
if (k === symbols.is_proxy)
|
|
1340
1346
|
return true
|
|
1341
1347
|
if (typeof k === 'symbol')
|
|
@@ -1343,7 +1349,7 @@
|
|
|
1343
1349
|
|
|
1344
1350
|
// Compute the new path
|
|
1345
1351
|
var new_path = path + '[' + JSON.stringify(k) + ']'
|
|
1346
|
-
return item_proxy(base, new_path, o[escape_field_to_bus(k)])
|
|
1352
|
+
return item_proxy(base, new_path, o[escape_field_to_nelson(escape_field_to_bus(k))])
|
|
1347
1353
|
},
|
|
1348
1354
|
set: function set(o, k, v) {
|
|
1349
1355
|
var value = translate_fields(v, field => escape_field_to_bus(escape_field_to_nelson(field)))
|
|
@@ -1357,6 +1363,8 @@
|
|
|
1357
1363
|
return true
|
|
1358
1364
|
},
|
|
1359
1365
|
has: function has(o, k) {
|
|
1366
|
+
// if (custom_inspect && k === custom_inspect)
|
|
1367
|
+
// return true
|
|
1360
1368
|
return o.hasOwnProperty(escape_field_to_bus(k))
|
|
1361
1369
|
},
|
|
1362
1370
|
deleteProperty: function del (o, k) {
|
|
@@ -1423,7 +1431,7 @@
|
|
|
1423
1431
|
header: function (x) {
|
|
1424
1432
|
if (x[symbols.is_proxy])
|
|
1425
1433
|
return ['span', {style: 'background-color: #fffbe5; padding: 3px;'},
|
|
1426
|
-
JSON.stringify(x)]
|
|
1434
|
+
JSON.stringify(unescape_from_nelson(unescape_from_bus(x)))]
|
|
1427
1435
|
// For function proxies:
|
|
1428
1436
|
// JSON.stringify(x(), null, 2)]
|
|
1429
1437
|
},
|
|
@@ -1737,7 +1745,8 @@
|
|
|
1737
1745
|
else if (typeof json === 'object' && json !== null) {
|
|
1738
1746
|
var new_obj = {}
|
|
1739
1747
|
for (var k in json)
|
|
1740
|
-
|
|
1748
|
+
if (typeof k === 'string')
|
|
1749
|
+
new_obj[translate(k, json)] = translate_fields(json[k], translate)
|
|
1741
1750
|
result = new_obj
|
|
1742
1751
|
}
|
|
1743
1752
|
|
|
@@ -1755,16 +1764,20 @@
|
|
|
1755
1764
|
// - nelSON escapes link -> _link
|
|
1756
1765
|
// - JSON
|
|
1757
1766
|
//
|
|
1758
|
-
var escape_field_to_bus = (field) => field
|
|
1759
|
-
unescape_field_from_bus = (field) => field
|
|
1760
|
-
escape_field_to_nelson = (field) => field
|
|
1761
|
-
unescape_field_from_nelson = (field) => field
|
|
1767
|
+
var escape_field_to_bus = (field) => field_replace(field, /^(_*)key$/, '$1_key'),
|
|
1768
|
+
unescape_field_from_bus = (field) => field_replace(field, /^(_*)_key$/, '$1key'),
|
|
1769
|
+
escape_field_to_nelson = (field) => field_replace(field, /^(_*)link$/, '$1_link'),
|
|
1770
|
+
unescape_field_from_nelson = (field) => field_replace(field, /^(_*)_link$/, '$1link')
|
|
1762
1771
|
|
|
1763
1772
|
var escape_to_bus = (obj) => translate_fields(obj, escape_field_to_bus)
|
|
1764
1773
|
unescape_from_bus = (obj) => translate_fields(obj, unescape_field_from_bus)
|
|
1765
1774
|
escape_to_nelson = (obj) => translate_fields(obj, escape_field_to_nelson)
|
|
1766
1775
|
unescape_from_nelson = (obj) => translate_fields(obj, unescape_field_from_nelson)
|
|
1767
1776
|
|
|
1777
|
+
var field_replace = (field, pattern, replacement) => (typeof field === 'string'
|
|
1778
|
+
? field.replace(pattern, replacement)
|
|
1779
|
+
: field)
|
|
1780
|
+
|
|
1768
1781
|
function key_id(string) { return string.match(/\/?[^\/]+\/(\d+)/)[1] }
|
|
1769
1782
|
function key_name(string) { return string.match(/\/?([^\/]+).*/)[1] }
|
|
1770
1783
|
|