Skip to content

Commit 64be66b

Browse files
committed
Start writing about used solid dev apis and internals
1 parent a9c23a4 commit 64be66b

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

used-solid.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Current usage
2+
3+
## Props
4+
5+
- `solid.$PROXY` is used to check if the props object is a proxy
6+
7+
- If it's not a proxy, I can patch it with `Object.defineProperty(props, key, {get})` to intercept accessing props—since accessing props might cause side-effects I have to wait for the user.
8+
- https://github.com/thetarnav/solid-devtools/blob/main/packages/debugger/src/inspector/inspector.ts#L98-L113
9+
- `solid.getListener() + solid.onCleanup()` is useful there to know when the prop is no longer being listened to—I might not have the latest value anymore.
10+
11+
- For proxy props I can only get keys with `Object.keys(props)`
12+
13+
### Issues
14+
15+
- I cannot intercept proxy props—users just see `foo: unknown` without the value
16+
17+
- props object cannot be changed, just monkeypatched—replacing it would probably let me intercept reads to proxy props
18+
19+
- `solid.DEV.hooks.afterCreateOwner()` gets called before `props` are attached to the owner, so I cannot get to them then.
20+
21+
- so currently I cannot intercept the initial reads from props—which are the most common
22+
- I would have to do `Object.defineProperty(owner, "props", {set})` to be able to patch props before component function executes probably
23+
- https://github.com/solidjs/solid/blob/main/packages/solid/src/reactive/signal.ts#L1115-L1133
24+
25+
## Store
26+
27+
- `store.unwrap()` with type reflection when serializing and reading stores
28+
29+
- `store.isWrappable()`
30+
31+
- `store.DEV.hooks.onStoreNodeUpdate()` for observing changes to stores
32+
- https://github.com/thetarnav/solid-devtools/blob/main/packages/debugger/src/inspector/store.ts#L27-L49
33+
34+
### Issues
35+
36+
- There is no connection between signals and the store-nodes they are being used in.
37+
So if there is an effect that listens to some store property *(e.g. `createEffect(() => store.foo)`)*, from devtools perspective this is just some random signal being observed in `owner.sources`
38+
39+
## Owner tree
40+
41+
- `solid.DEV.hooks.afterCreateOwner()` for attaching the debugger to roots
42+
- to gather top-level roots like `render()`
43+
- but also to "re-attach roots back to the owner tree" when `createRoot` is used under owners, like in `mapArray`
44+
- https://github.com/thetarnav/solid-devtools/blob/main/packages/debugger/src/main/roots.ts#L147-L163
45+
- access to `owner.owner` and `owner.cleanups` to listen to parent's *(root's detached owner)* cleanup
46+
- so that if the root's parent disposes before the root, the root will need to be "reattached" to first found "alive" owner
47+
- this is rather uncommon
48+
49+
- patching `owner.cleanups` to listen to cleanup of any owner
50+
- https://github.com/thetarnav/solid-devtools/blob/main/packages/debugger/src/main/utils.ts#L205-L227
51+
52+
- `owner.owned`
53+
54+
## Computations
55+
56+
- `owner.value` + patching the value
57+
- `owner.sources`
58+
- `owner.observers`
59+
60+
## Source Map
61+
62+
- `solid.DEV.hooks.afterCreateSignal()`
63+
- `solid.DEV.registerGraph()`
64+
- `owner.sourceMap`
65+
66+
## List
67+
- `solid.$PROXY` in [props](#props)
68+
- `Object.defineProperty(props, key, {get})` in [props](#props)
69+
- `solid.getListener() + solid.onCleanup()` in [props](#props)
70+
- `store.unwrap()` in [store](#store)
71+
- `store.isWrappable()` in [store](#store)
72+
- `store.DEV.hooks.onStoreNodeUpdate()` in [store](#store)
73+
- `solid.DEV.hooks.afterCreateOwner()` in [owners](#owners)
74+
- `owner.owner` in [owners](#owners)
75+
- `owner.cleanups` in [owners](#owners)
76+
77+
# Future
78+
- `onOwnerCleanup` - to not patch `owner.cleanups`
79+
- it probably would be useful to have both `onBeforeOwnerCleanup` and `onAfterOwnerCleanup`
80+
as the cleanups are executed depth first—if I try to walk the tree on child's cleanup, I cannot tell if the parent is getting cleaned up as well or not.

0 commit comments

Comments
 (0)