Skip to content

Commit

Permalink
Remove no longer needed check for Arbor instances when scoping child …
Browse files Browse the repository at this point in the history
…access
  • Loading branch information
drborges committed Sep 10, 2024
1 parent da26ff1 commit f83c8af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
2 changes: 2 additions & 0 deletions packages/arbor-store/src/handlers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const PROXY_HANDLER_API = ["apply", "get", "set", "deleteProperty"]
export class DefaultHandler<T extends object = object>
implements ProxyHandler<T>
{
// TODO: Move $ prefixed props to Symbol properties.
// This will mitigate potential naming clashes with user-defined data.
constructor(
readonly $tree: Arbor,
readonly $value: T,
Expand Down
26 changes: 7 additions & 19 deletions packages/arbor-store/src/scoping/scope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Arbor } from "../arbor"
import { isDetachedProperty } from "../decorators"
import { isNode } from "../guards"
import { Seed } from "../path"
Expand Down Expand Up @@ -117,10 +116,12 @@ export class Scope<T extends object> {

return new Proxy(node, {
get(target: Node, prop, proxy) {
// TODO: Rename $tracked to Symbol.for("ArborScoped")
if (prop === "$tracked") {
return true
}

// Exposes the node wrapped by the proxy
if (prop === "$value") {
return target
}
Expand All @@ -142,12 +143,10 @@ export class Scope<T extends object> {
}
}

// TODO: find a solution that does not involve overriding a possible get method
// on the target...
//
// TODO: handlers/map.ts must intercept child access so it can proxy them
// otherwise, accessing a child from a scoped map will not yield a scoped
// child but the actual underlying value.
// TODO: Look into making this logic generic.
// We need a mechanism where node handlers can declare a few methods in the underlying
// object signaling that it returns a child node, allowing Arbor to intercept that access
// adding extra behavior such as scoping/path tracking capabilities like below.
if (target instanceof Map && prop === "get") {
return (link: Link) => {
const child = target.get(link)
Expand Down Expand Up @@ -195,18 +194,7 @@ export class Scope<T extends object> {
track(target, prop)
}

if (
child == null ||
// There's no point in tracking access to Arbor stores being referenced
// without other stores since they are not connected to each other.
// Also, we cannot proxy Arbor instance since itself relies on #private
// fields to hide internal concerns which gets in the way of the proxying
// mechanism.
//
// See "Private Properties" section of the Caveats.md for more details.
child instanceof Arbor ||
typeof child !== "object"
) {
if (!isNode(child)) {
return child
}

Expand Down

0 comments on commit f83c8af

Please sign in to comment.