statebus 7.2.3 → 7.2.4
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 +20 -6
- package/package.json +1 -1
- package/statebus.js +30 -25
package/extras/tests.js
CHANGED
|
@@ -1129,17 +1129,14 @@ test(function proxies (done) {
|
|
|
1129
1129
|
|
|
1130
1130
|
state.foo = 3
|
|
1131
1131
|
// This should set into _
|
|
1132
|
-
|
|
1133
|
-
{key: 'foo', _: 3}))
|
|
1132
|
+
assert(bus.validate(bus.cache.foo, {key: 'foo', _: 3}))
|
|
1134
1133
|
|
|
1135
1134
|
|
|
1136
1135
|
state.foo = {a: 5}
|
|
1137
1136
|
// This should set directly on it
|
|
1138
|
-
|
|
1139
|
-
{key: 'foo', a: 5}))
|
|
1137
|
+
assert(bus.validate(bus.cache.foo, {key: 'foo', a: 5}))
|
|
1140
1138
|
state.foo.b = 6
|
|
1141
|
-
|
|
1142
|
-
{key: 'foo', b: 6}))
|
|
1139
|
+
assert(bus.validate(bus.cache.foo, {key: 'foo', b: 6}))
|
|
1143
1140
|
|
|
1144
1141
|
state.bar = [3]
|
|
1145
1142
|
state.foo = {a: 3, bar: state.bar}
|
|
@@ -1158,6 +1155,23 @@ test(function proxies (done) {
|
|
|
1158
1155
|
// Getting a normal property should do a get
|
|
1159
1156
|
})
|
|
1160
1157
|
|
|
1158
|
+
test(function proxy_link_escaping (done) {
|
|
1159
|
+
var bus = require('../statebus')()
|
|
1160
|
+
var state = bus.state
|
|
1161
|
+
|
|
1162
|
+
// See that links get escaped
|
|
1163
|
+
state.foo = {link: "bar"}
|
|
1164
|
+
assert(bus.validate(bus.cache.foo,
|
|
1165
|
+
{key: "foo", val: {_link: "bar"}}))
|
|
1166
|
+
|
|
1167
|
+
// And unescaped
|
|
1168
|
+
// log("state.foo", state.foo)
|
|
1169
|
+
// log("state.foo", JSON.stringify(state.foo))
|
|
1170
|
+
assert(bus.validate(state.foo, {link: "bar"}))
|
|
1171
|
+
|
|
1172
|
+
done()
|
|
1173
|
+
})
|
|
1174
|
+
|
|
1161
1175
|
test(function path_parts (done) {
|
|
1162
1176
|
bus.honk = 3
|
|
1163
1177
|
bus('path/:part1/:part2/stuff/:part3/more*').getter = function (key, path, t) {
|
package/package.json
CHANGED
package/statebus.js
CHANGED
|
@@ -1487,6 +1487,7 @@
|
|
|
1487
1487
|
return true // Report success to Proxy
|
|
1488
1488
|
}
|
|
1489
1489
|
})
|
|
1490
|
+
bus.state = top_level_proxy
|
|
1490
1491
|
|
|
1491
1492
|
// The proxy within; a recursive tree holds each piece of JSON in a resource
|
|
1492
1493
|
function json_proxy (base, path, o) {
|
|
@@ -1533,6 +1534,8 @@
|
|
|
1533
1534
|
|
|
1534
1535
|
var proxy = new Proxy(target, {
|
|
1535
1536
|
get: function (o, k) {
|
|
1537
|
+
// console.log('proxy get:', o, k)
|
|
1538
|
+
|
|
1536
1539
|
if (k === 'inspect' || k === 'valueOf')
|
|
1537
1540
|
return undefined
|
|
1538
1541
|
if (k === symbols.is_proxy)
|
|
@@ -1564,15 +1567,17 @@
|
|
|
1564
1567
|
)
|
|
1565
1568
|
return true
|
|
1566
1569
|
},
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1570
|
+
has: function (o, k) {
|
|
1571
|
+
return o.hasOwnProperty(escape_field_json_to_bus(k))
|
|
1572
|
+
},
|
|
1573
|
+
ownKeys: function () {
|
|
1574
|
+
return Object.keys(target).map(unescape_field_bus_to_json)
|
|
1575
|
+
},
|
|
1576
|
+
getOwnPropertyDescriptor: function (target, key) {
|
|
1577
|
+
return { enumerable: true, configurable: true,
|
|
1578
|
+
value: this.get(target, escape_field_json_to_bus(key))
|
|
1579
|
+
}
|
|
1580
|
+
},
|
|
1576
1581
|
deleteProperty: function del (target, k) {
|
|
1577
1582
|
var new_path = path + '[' + JSON.stringify(k) + ']'
|
|
1578
1583
|
var escaped_key = escape_field_json_to_bus(k)
|
|
@@ -1592,8 +1597,6 @@
|
|
|
1592
1597
|
return proxy
|
|
1593
1598
|
}
|
|
1594
1599
|
|
|
1595
|
-
bus.state = top_level_proxy
|
|
1596
|
-
|
|
1597
1600
|
// This doesn't work because custom inspectors only work when the
|
|
1598
1601
|
// util.inspect.custom symbol is defined on the "target" of the
|
|
1599
1602
|
// proxy... which right now is `cache` for the top_level_proxy. I could
|
|
@@ -1612,20 +1615,22 @@
|
|
|
1612
1615
|
// }
|
|
1613
1616
|
// }
|
|
1614
1617
|
|
|
1615
|
-
// This is
|
|
1616
|
-
//
|
|
1617
|
-
//
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
}
|
|
1618
|
+
// This is disabled because it's not being used.
|
|
1619
|
+
//
|
|
1620
|
+
// // This is temporary code to wrap the cache as a flat key/valuel store
|
|
1621
|
+
// // that returns raw objects, dereferencing .val. We can remove it once we
|
|
1622
|
+
// // remove the internal .val stuff from statebus.
|
|
1623
|
+
// function raw_proxy () {
|
|
1624
|
+
// return new Proxy(cache, {
|
|
1625
|
+
// get: function get(o, k) { return bus.cache[k].val },
|
|
1626
|
+
// set: function set(o, key, val) {
|
|
1627
|
+
// return false
|
|
1628
|
+
// },
|
|
1629
|
+
// deleteProperty: function del (o, k) {
|
|
1630
|
+
// return false
|
|
1631
|
+
// }
|
|
1632
|
+
// })
|
|
1633
|
+
// }
|
|
1629
1634
|
|
|
1630
1635
|
|
|
1631
1636
|
// Old link code:
|