Skip to content

Commit

Permalink
More fixes to proxy business
Browse files Browse the repository at this point in the history
  • Loading branch information
toomim committed May 11, 2024
1 parent 33fe2f3 commit 83118a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "statebus",
"version": "7.0.27",
"version": "7.0.28",
"description": "Synchronize state.",
"main": "statebus.js",
"scripts": {
Expand Down
25 changes: 16 additions & 9 deletions statebus.js
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@


return new Proxy(o, {
get: function get(o, k) {
get: function (o, k) {
if (k === 'inspect' || k === 'valueOf')
return undefined
// if (custom_inspect && k === custom_inspect)
Expand All @@ -1349,11 +1349,11 @@

// Compute the new path
var new_path = path + '[' + JSON.stringify(k) + ']'
return item_proxy(base, new_path, o[escape_field_to_nelson(escape_field_to_bus(k))])
return item_proxy(base, new_path, o[escape_field_to_bus(escape_field_to_nelson(k))])
},
set: function set(o, k, v) {
set: function (o, k, v) {
var value = translate_fields(v, field => escape_field_to_bus(escape_field_to_nelson(field)))
o[escape_field_to_bus(k)] = value
o[escape_field_to_bus(escape_field_to_nelson(k))] = value
var new_path = path + '[' + JSON.stringify(k) + ']'
bus.set(
base,
Expand All @@ -1362,14 +1362,20 @@
)
return true
},
has: function has(o, k) {
has: function (o, k) {
// if (custom_inspect && k === custom_inspect)
// return true
return o.hasOwnProperty(escape_field_to_bus(k))
return o.hasOwnProperty(escape_field_to_bus(escape_field_to_nelson(k)))
},
ownKeys: function () {
return Object.keys(o).map(unescape_field_from_nelson).map(unescape_field_from_bus)
},
getOwnPropertyDescriptor: function (target, key) {
return { enumerable: true, configurable: true, value: this.get(o, key) }
},
deleteProperty: function del (o, k) {
var new_path = path + '[' + JSON.stringify(k) + ']'
delete o[escape_field_to_bus(k)]
delete o[escape_field_to_bus(escape_field_to_nelson(k))]
bus.set(
base,
// Forward the patch too
Expand Down Expand Up @@ -1429,9 +1435,10 @@
if (!nodejs)
window.devtoolsFormatters = [{
header: function (x) {
if (x[symbols.is_proxy])
if (x[symbols.is_proxy]) {
return ['span', {style: 'background-color: #fffbe5; padding: 3px;'},
JSON.stringify(unescape_from_nelson(unescape_from_bus(x)))]
JSON.stringify(x)]
}
// For function proxies:
// JSON.stringify(x(), null, 2)]
},
Expand Down

0 comments on commit 83118a6

Please sign in to comment.