-
Notifications
You must be signed in to change notification settings - Fork 2
Arbor OST #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
drborges
wants to merge
52
commits into
main
Choose a base branch
from
arbor-ost
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Arbor OST #146
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
18ed918
Initial prototype of the observable state tree package
drborges 7319d90
Implement basis of OST lazy initialization
drborges e349844
Apply node variable naming convention
drborges 893777e
Implement test matcher to make it easier to check if a node exists in…
drborges 02c93f1
Remove unnecessary ost folder
drborges 3c91a91
Binds 'this' in methods to the corresponding OST node
drborges efdcf86
Handle 'set' mutations triggered by an OST node
drborges ef2e87e
Attempt to recursively type state tree nodes
drborges d79b184
Add test coverage to Node# iterator
drborges d89383f
Allow passing OST root state via constructor
drborges a3ded7d
Polish subscription system
drborges 181ec4c
Implement object handler's delete trap
drborges dbc5117
Add support to custom types and getters
drborges 0fa4e82
Allow detached class properties
drborges aa2f167
Implement Node's Symbol.toStringTag
drborges 1260ed4
Return mutated node from OST#mutate
drborges 442b488
Create mutation helpers to make it easier to reuse common opeartions
drborges 271c5e3
Implement $array handler
drborges bb2c80f
Implement visitor pattern to make it easier to extend OST proxying me…
drborges 71b1643
Implement pop visitor for handling Array#pop
drborges 6b4f200
Implement shift visitor for handling Array#shift
drborges 8916b7a
Implement unshift visitor for handling Array#unshift
drborges 370abf7
Improve subscription metadata API
drborges 3d9b462
Add .tool-versions
drborges e3cf660
Implement reverse visitor for handling Array#reverse
drborges 9e5759b
Simplify OST subscription metadata
drborges fe9f8f8
Implement copyWithin visitor for handling Array#copyWithin
drborges 94e6b72
Ensure visitors are created only once
drborges fb90aa9
Implement test coverage for Array#splice
drborges 8085526
Implement Array#fill visitor
drborges 8fc2237
Fix type declarations of vitest custom matchers
drborges 59095d9
Remove unnecessary console.log
drborges e8a1b6d
Apply small optimizations
drborges ee44a4f
Fix test coverage for Node#
drborges 97295a9
Remove bad conflict resolution
drborges f0317fc
Add support to Map nodes
drborges c16931f
Add some more test coverage to array handler
drborges bd7b002
Optimize visitor matching logic
drborges 6f1ece7
Avoid redundant childValue resolution
drborges 3da4f3f
Move proxiable logic closer together for better locality of behavior
drborges 2a48daf
Add support to Set nodes
drborges 7973094
Implement remaining of Set visitors via Claude's agentic mode
drborges 16ffc9a
Fix linting and TS errors around recently added Set API spec changes
drborges a0fac4b
Increase test coverage for array nodes
drborges c8a45f9
Add support to WeakSet and WeakMap as OST nodes
drborges 400c588
Organize handlers and visitors to make codebase navigation easier
drborges 23b4db3
Remove unnecessary indirection on mutation logic
drborges 6368b25
Clean up code and remove some duplication
drborges 8c372be
Allow traversing of Map and Set nodes
drborges 62c7306
Implement foundation for OST scoping
drborges fbea5d6
Implement scope handlers for better encapsulation
drborges 04e5700
WIP
drborges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| nodejs 23.11.0 | ||
| yarn 1.22.22 |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // Project-local debug tasks | ||
| // | ||
| // For more documentation on how to configure debug tasks, | ||
| // see: https://zed.dev/docs/debugger | ||
| [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "extends": ["../../.eslintrc.json"], | ||
| "ignorePatterns": ["perf"], | ||
| "parserOptions": { | ||
| "project": ["./tsconfig.eslint.json"] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| dist/ | ||
| **/dist/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| { | ||
| "name": "@arborjs/ost", | ||
| "sideEffects": false, | ||
| "version": "0.0.1-alpha.1", | ||
| "description": "An observable state tree data structure used to power @arborjs/store.", | ||
| "keywords": [ | ||
| "arbor", | ||
| "react", | ||
| "state", | ||
| "store", | ||
| "typescript", | ||
| "tree" | ||
| ], | ||
| "repository": { | ||
| "url": "https://github.com/drborges/arbor", | ||
| "type": "git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/drborges/arbor/issues", | ||
| "email": "drborges.cic@gmail.com" | ||
| }, | ||
| "author": { | ||
| "email": "drborges.cic@gmail.com", | ||
| "name": "Diego Borges", | ||
| "url": "https://github.com/drborges" | ||
| }, | ||
| "main": "./dist/index.cjs.js", | ||
| "module": "./dist/index.esm.js", | ||
| "types": "./dist/index.d.ts", | ||
| "type": "module", | ||
| "exports": { | ||
| ".": { | ||
| "require": "./dist/index.cjs.js", | ||
| "import": "./dist/index.esm.js", | ||
| "default": "./dist/index.esm.js" | ||
| } | ||
| }, | ||
| "license": "MIT", | ||
| "prettier": "@arborjs/config-prettier", | ||
| "files": [ | ||
| "./dist", | ||
| "./README", | ||
| "../../LICENSE" | ||
| ], | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "devDependencies": { | ||
| "esbuild": "^0.17.19", | ||
| "eslint": "^8.40.0", | ||
| "prettier": "^2.8.8", | ||
| "typescript": "^5.0.4", | ||
| "vitest": "^1.6.0" | ||
| }, | ||
| "scripts": { | ||
| "prettier": "prettier -w . ", | ||
| "clean": "rm -rf dist", | ||
| "lint": "yarn eslint . --ext .js,.jsx,.ts,.tsx", | ||
| "test": "vitest run", | ||
| "dev": "vitest -w", | ||
| "build": "yarn clean && NODE_ENV=production node ../../tools/build.js && yarn tsc", | ||
| "build:dev": "yarn clean && NODE_ENV=development node ../../tools/build.js && yarn tsc" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export const ArborDetached = Symbol.for("ArborDetached") | ||
|
|
||
| export function detached(target: unknown, prop: unknown) { | ||
| target[ArborDetached] = target[ArborDetached] || {} | ||
| const detachedProps = target[ArborDetached] | ||
| detachedProps[prop] = true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| export const ArborProxiable = Symbol.for("ArborProxiable") | ||
|
|
||
| /** | ||
| * Make application classes eligible for being used as nodes in the Arbor state tree. | ||
| * | ||
| * @example | ||
| * | ||
| * ```ts | ||
| * @node | ||
| * class Todo { | ||
| * text: string | ||
| * } | ||
| * ``` | ||
| */ | ||
| export function node<T extends Function>(target: T, _context: unknown = null) { | ||
| target.prototype[ArborProxiable] = true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export class ArborError extends Error {} | ||
|
|
||
| export class DetachedPathError extends ArborError { | ||
| constructor(humanizedPath: string) { | ||
| super( | ||
| `Path ${humanizedPath} is detached from the tree. Cannot perform mutation.` | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { OST } from "../../ost" | ||
| import { $object } from "./../$object" | ||
| import { PopVisitor } from "./visitors/pop" | ||
| import { PushVisitor } from "./visitors/push" | ||
| import { ShiftVisitor } from "./visitors/shift" | ||
| import { SpliceVisitor } from "./visitors/splice" | ||
| import { UnshiftVisitor } from "./visitors/unshift" | ||
| import { ReverseVisitor } from "./visitors/reverse" | ||
| import { CopyWithinVisitor } from "./visitors/copyWithin" | ||
| import { FillVisitor } from "./visitors/fill" | ||
| import { Visitors } from "../visitors" | ||
|
|
||
| const visitors = new Visitors( | ||
| new PushVisitor(), | ||
| new PopVisitor(), | ||
| new ShiftVisitor(), | ||
| new UnshiftVisitor(), | ||
| new ReverseVisitor(), | ||
| new SpliceVisitor(), | ||
| new CopyWithinVisitor(), | ||
| new FillVisitor() | ||
| ) | ||
|
|
||
| export class $array extends $object { | ||
| constructor(ost: OST) { | ||
| super(ost, visitors) | ||
| } | ||
|
|
||
| static accepts(value: unknown): boolean { | ||
| return Array.isArray(value) | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
packages/arbor-ost/src/handlers/$array/visitors/copyWithin.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Visitor } from "../../visitor" | ||
|
|
||
| export class CopyWithinVisitor extends Visitor { | ||
| prop = "copyWithin" | ||
|
|
||
| visit({ ost, target, $node }) { | ||
| return (...args: unknown[]) => { | ||
| return ost.mutate($node, () => { | ||
| target.copyWithin(...args) | ||
|
|
||
| return { | ||
| args: args, | ||
| operation: "copyWithin", | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Visitor } from "../../visitor" | ||
|
|
||
| export class FillVisitor extends Visitor { | ||
| prop = "fill" | ||
|
|
||
| visit({ ost, target, $node }) { | ||
| return (...args: unknown[]) => { | ||
| return ost.mutate($node, () => { | ||
| target.fill(...args) | ||
|
|
||
| return { | ||
| args: args, | ||
| operation: "fill", | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { Visitor } from "../../visitor" | ||
|
|
||
| export class PopVisitor extends Visitor { | ||
| prop = "pop" | ||
|
|
||
| visit({ ost, target, $node }) { | ||
| return () => { | ||
| let popped: unknown | ||
|
|
||
| ost.mutate($node, () => { | ||
| popped = target.pop() | ||
|
|
||
| return { | ||
| args: [], | ||
| operation: "pop", | ||
| } | ||
| }) | ||
|
|
||
| return popped | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { Visitor } from "../../visitor" | ||
| import { Value } from "../../../types" | ||
|
|
||
| export class PushVisitor extends Visitor { | ||
| prop = "push" | ||
|
|
||
| visit({ ost, target, $node }) { | ||
| return (...items: Value[]) => { | ||
| let length: number | ||
|
|
||
| ost.mutate($node, () => { | ||
| length = target.push(...items) | ||
|
|
||
| return { | ||
| args: [items], | ||
| operation: "push", | ||
| } | ||
| }) | ||
|
|
||
| return length | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
packages/arbor-ost/src/handlers/$array/visitors/reverse.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Visitor } from "../../visitor" | ||
|
|
||
| export class ReverseVisitor extends Visitor { | ||
| prop = "reverse" | ||
|
|
||
| visit({ ost, target, $node }) { | ||
| return () => { | ||
| return ost.mutate($node, () => { | ||
| target.reverse() | ||
|
|
||
| return { | ||
| args: [], | ||
| operation: "reverse", | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { Visitor } from "../../visitor" | ||
|
|
||
| export class ShiftVisitor extends Visitor { | ||
| prop = "shift" | ||
|
|
||
| visit({ ost, target, $node }) { | ||
| return () => { | ||
| let removed: unknown | ||
|
|
||
| ost.mutate($node, () => { | ||
| removed = target.shift() | ||
|
|
||
| return { | ||
| args: [], | ||
| operation: "shift", | ||
| } | ||
| }) | ||
|
|
||
| return removed | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { Visitor } from "../../visitor" | ||
|
|
||
| export class SpliceVisitor extends Visitor { | ||
| prop = "splice" | ||
|
|
||
| visit({ ost, target, $node }) { | ||
| return ( | ||
| start: number, | ||
| deleteCount: number, | ||
| ...items: unknown[] | ||
| ): unknown[] => { | ||
| let deleted: unknown[] | ||
|
|
||
| ost.mutate($node, () => { | ||
| deleted = target.splice(start, deleteCount, ...items) | ||
|
|
||
| return { | ||
| args: [start, deleteCount, items], | ||
| operation: "splice", | ||
| } | ||
| }) | ||
|
|
||
| return deleted | ||
| } | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
packages/arbor-ost/src/handlers/$array/visitors/unshift.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { Visitor } from "../../visitor" | ||
|
|
||
| export class UnshiftVisitor extends Visitor { | ||
| prop = "unshift" | ||
|
|
||
| visit({ ost, target, $node }) { | ||
| return (...args: unknown[]) => { | ||
| let unshifted: unknown[] | ||
|
|
||
| ost.mutate($node, () => { | ||
| unshifted = target.unshift(...args) | ||
|
|
||
| return { | ||
| args: [args], | ||
| operation: "unshift", | ||
| } | ||
| }) | ||
|
|
||
| return unshifted | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { OST } from "../../ost" | ||
| import { $object } from "./../$object" | ||
| import { Visitors } from "../visitors" | ||
| import { GetVisitor } from "./visitors/get" | ||
| import { SetVisitor } from "./visitors/set" | ||
| import { SizeVisitor } from "./visitors/size" | ||
| import { DeleteVisitor } from "./visitors/delete" | ||
| import { ClearVisitor } from "./visitors/clear" | ||
| import { EntriesVisitor } from "./visitors/entries" | ||
| import { ForEachVisitor } from "./visitors/forEach" | ||
| import { HasVisitor } from "./visitors/has" | ||
| import { KeysVisitor } from "./visitors/keys" | ||
| import { ValuesVisitor } from "./visitors/values" | ||
| import { IteratorVisitor } from "./visitors/iterator" | ||
| import { ChildrenVisitor } from "./visitors/$children" | ||
|
|
||
| const visitors = new Visitors( | ||
| new ChildrenVisitor(), | ||
| new GetVisitor(), | ||
| new SetVisitor(), | ||
| new SizeVisitor(), | ||
| new DeleteVisitor(), | ||
| new ClearVisitor(), | ||
| new EntriesVisitor(), | ||
| new ForEachVisitor(), | ||
| new HasVisitor(), | ||
| new KeysVisitor(), | ||
| new ValuesVisitor(), | ||
| new IteratorVisitor() | ||
| ) | ||
|
|
||
| export class $map extends $object { | ||
| constructor(ost: OST) { | ||
| super(ost, visitors) | ||
| } | ||
|
|
||
| static accepts(value: unknown): boolean { | ||
| return value instanceof Map | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
unshiftmethod returns a number (the new length), but the variable is typed asunknown[]. The assignment should beunshifted = target.unshift(...args)and the return type should benumber.