statebus 7.0.26 → 7.0.28
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 +33 -13
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
|
|
@@ -1333,9 +1337,11 @@
|
|
|
1333
1337
|
|
|
1334
1338
|
|
|
1335
1339
|
return new Proxy(o, {
|
|
1336
|
-
get: function
|
|
1340
|
+
get: function (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,11 +1349,11 @@
|
|
|
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_bus(escape_field_to_nelson(k))])
|
|
1347
1353
|
},
|
|
1348
|
-
set: function
|
|
1354
|
+
set: function (o, k, v) {
|
|
1349
1355
|
var value = translate_fields(v, field => escape_field_to_bus(escape_field_to_nelson(field)))
|
|
1350
|
-
o[escape_field_to_bus(k)] = value
|
|
1356
|
+
o[escape_field_to_bus(escape_field_to_nelson(k))] = value
|
|
1351
1357
|
var new_path = path + '[' + JSON.stringify(k) + ']'
|
|
1352
1358
|
bus.set(
|
|
1353
1359
|
base,
|
|
@@ -1356,12 +1362,20 @@
|
|
|
1356
1362
|
)
|
|
1357
1363
|
return true
|
|
1358
1364
|
},
|
|
1359
|
-
has: function
|
|
1360
|
-
|
|
1365
|
+
has: function (o, k) {
|
|
1366
|
+
// if (custom_inspect && k === custom_inspect)
|
|
1367
|
+
// return true
|
|
1368
|
+
return o.hasOwnProperty(escape_field_to_bus(escape_field_to_nelson(k)))
|
|
1369
|
+
},
|
|
1370
|
+
ownKeys: function () {
|
|
1371
|
+
return Object.keys(o).map(unescape_field_from_nelson).map(unescape_field_from_bus)
|
|
1372
|
+
},
|
|
1373
|
+
getOwnPropertyDescriptor: function (target, key) {
|
|
1374
|
+
return { enumerable: true, configurable: true, value: this.get(o, key) }
|
|
1361
1375
|
},
|
|
1362
1376
|
deleteProperty: function del (o, k) {
|
|
1363
1377
|
var new_path = path + '[' + JSON.stringify(k) + ']'
|
|
1364
|
-
delete o[escape_field_to_bus(k)]
|
|
1378
|
+
delete o[escape_field_to_bus(escape_field_to_nelson(k))]
|
|
1365
1379
|
bus.set(
|
|
1366
1380
|
base,
|
|
1367
1381
|
// Forward the patch too
|
|
@@ -1421,9 +1435,10 @@
|
|
|
1421
1435
|
if (!nodejs)
|
|
1422
1436
|
window.devtoolsFormatters = [{
|
|
1423
1437
|
header: function (x) {
|
|
1424
|
-
if (x[symbols.is_proxy])
|
|
1438
|
+
if (x[symbols.is_proxy]) {
|
|
1425
1439
|
return ['span', {style: 'background-color: #fffbe5; padding: 3px;'},
|
|
1426
1440
|
JSON.stringify(x)]
|
|
1441
|
+
}
|
|
1427
1442
|
// For function proxies:
|
|
1428
1443
|
// JSON.stringify(x(), null, 2)]
|
|
1429
1444
|
},
|
|
@@ -1737,7 +1752,8 @@
|
|
|
1737
1752
|
else if (typeof json === 'object' && json !== null) {
|
|
1738
1753
|
var new_obj = {}
|
|
1739
1754
|
for (var k in json)
|
|
1740
|
-
|
|
1755
|
+
if (typeof k === 'string')
|
|
1756
|
+
new_obj[translate(k, json)] = translate_fields(json[k], translate)
|
|
1741
1757
|
result = new_obj
|
|
1742
1758
|
}
|
|
1743
1759
|
|
|
@@ -1755,16 +1771,20 @@
|
|
|
1755
1771
|
// - nelSON escapes link -> _link
|
|
1756
1772
|
// - JSON
|
|
1757
1773
|
//
|
|
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
|
|
1774
|
+
var escape_field_to_bus = (field) => field_replace(field, /^(_*)key$/, '$1_key'),
|
|
1775
|
+
unescape_field_from_bus = (field) => field_replace(field, /^(_*)_key$/, '$1key'),
|
|
1776
|
+
escape_field_to_nelson = (field) => field_replace(field, /^(_*)link$/, '$1_link'),
|
|
1777
|
+
unescape_field_from_nelson = (field) => field_replace(field, /^(_*)_link$/, '$1link')
|
|
1762
1778
|
|
|
1763
1779
|
var escape_to_bus = (obj) => translate_fields(obj, escape_field_to_bus)
|
|
1764
1780
|
unescape_from_bus = (obj) => translate_fields(obj, unescape_field_from_bus)
|
|
1765
1781
|
escape_to_nelson = (obj) => translate_fields(obj, escape_field_to_nelson)
|
|
1766
1782
|
unescape_from_nelson = (obj) => translate_fields(obj, unescape_field_from_nelson)
|
|
1767
1783
|
|
|
1784
|
+
var field_replace = (field, pattern, replacement) => (typeof field === 'string'
|
|
1785
|
+
? field.replace(pattern, replacement)
|
|
1786
|
+
: field)
|
|
1787
|
+
|
|
1768
1788
|
function key_id(string) { return string.match(/\/?[^\/]+\/(\d+)/)[1] }
|
|
1769
1789
|
function key_name(string) { return string.match(/\/?([^\/]+).*/)[1] }
|
|
1770
1790
|
|