Skip to content

Incorproate preact model, abstract VTree over underlying Node#1177

Merged
dmjio merged 24 commits into
masterfrom
patch
Nov 9, 2025
Merged

Incorproate preact model, abstract VTree over underlying Node#1177
dmjio merged 24 commits into
masterfrom
patch

Conversation

@dmjio
Copy link
Copy Markdown
Owner

@dmjio dmjio commented Oct 16, 2025

This adds patching (2-phase diffing) to miso's JS library (meant for use in miso-lynx). This allows patch objects to be transferred elsewhere for rendering (in the case of miso-lynx this is required, since it uses preact). This includes transferring event listener initialization, delegation of background events, component mounting / unmounting, and render tree diffing between threads via a Web Worker (or other) all using a well-defined protocol.

This patch abstracts VTree over the underlying DOMRef (or any other Node for that matter). In the case of miso-lynx, the Haskell runtime will hold a pure identifier, NodeId of type number, and the main thread runtime will hold references to the native device views.

Patch application includes an Environment that holds a NodeId mapping for each Node. This mapping is used to facilitate modifications to the tree in O(1) time.

This is PR 1/2 (the second occurring in miso-lynx) which will allow us to consume native components from iOS, Android, Harmony devices, etc. and to rely on the react-lynx plugin for code splitting.

  • Abstract VTree and Context over T in dom.ts, tests, etc.
  • Add patch.ts and additional types for runtime patching
  • Specialize hydrate.ts to DOMRef
  • Split up Context into HydrationContext and DrawingContext
  • Add nodeId to each VTree node (done in createElement on BTS side)
  • Test patch accumulation and patch application for applyPatch
  • Transfer JSON'ified model so read-only state is present for main thread events
  • Ensure NodeId can be used with event delegation
  • Test eval() of exported functions from Haskell for main thread events
  • Incorporate main thread events in Component (enable via flag w/ CPP)

EDIT: We will split this up into 3 PRs, one for Patches (done here), Component mounting / unmounting, and finally splitting up event delegation. This is step 1/3.

@dmjio dmjio force-pushed the patch branch 6 times, most recently from 0c66110 to 369feb9 Compare October 28, 2025 16:32
@dmjio dmjio force-pushed the patch branch 2 times, most recently from 80d8c65 to c35c2ac Compare November 4, 2025 19:24
dmjio and others added 16 commits November 7, 2025 23:06
This adds patching (2-phase diffing) to miso. This allows patch objects to be
transferred elsewhere for rendering (in the case of miso native
this is required). This includes transferring event listener initialization,
component mounting / unmounting, and render tree diffing.

This patch abstract `VTree` over the underlying `DOMRef`. In the Haskell
runtime it will be represented as a pure identifier (`NodeId` which
holds the pure identifier `number`).

Patch application includes an `Environment` that holds a `Node`
mapping for each `Component`. This mapping is used to faciliate
modifications to the tree in O(1) time.

- [x] Abstract `VTree` and `Context` over `T` in `dom.ts`, tests, etc.
- [x] Add `patch.ts` and additional types for runtime patching
- [ ] Add `nodeId` to each `VTree` node
- [ ] Test patch accumulation and patch application for `applyPatch`
- [ ] Ensure `NodeId` can be used with event delegation
- Generalizes `delegate` to `delegate<T>`, `undelegate<T>`, `dispatch`, etc.
- Add `removeEventListener`
- Add `context/dom.ts`
- cast `EventTarget` as `DOMRef` in `context`
…respectively.

- `setDrawingContext` now expects `globalThis[name].eventContext` and `globalThis[name].drawingContext` to be defined.
- Define `flush` on top-level `miso` object.
- `context` -> `drawingContext`, etc. Update tests to reflect this.
- Drop `.querySelectorAll()`.
- Update `Miso.Internal.FFI` to split out `getContext` into `getDrawingContext`, etc.
- Put `ts/index.ts` into `tsconfig.lib.json`
- Mock out patch.ts context.
- Add tag for vtext to satisfy TypeScript typechecker
dmjio added 3 commits November 8, 2025 16:10
- [x] Use `setProp`, avoid circular import issues
- [x] Add `mountComponent`, `unmountComponent`, `modelHydration` stubs
- [x] Drop event handling patches (will go into Component)
- [x] Refactor `globalThis.miso`
@dmjio dmjio merged commit 25ca704 into master Nov 9, 2025
2 checks passed
@dmjio dmjio deleted the patch branch November 9, 2025 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant