-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some long-needed renaming and consolidation (#90)Co-authored-by: Null…
…VoxPopuli <[email protected]> This commit holistic renames, consolidates, and cleans up internal concepts. * Rename "internal" concepts to Tag and Tagged * Simplify and improve the notion of subscriptions - @starbeam/runtime - @starbeam/tags - @starbeam/reactive - @starbeam/resource - @starbeam/service Previously, the implementation of tags lived in `TIMELINE`, which has a whole bunch of other unrelated stuff. So the abstraction went directly from the interfaces defined in `@starbeam/interfaces` to the full-fledged timeline definition in `@starbeam/timeline`. This created an awkward situation where tags ought to have been real objects (so they can share utility code), but we had utility function instead that worked with the interfaces to avoid dragging all of TIMELINE into the definition of tags. This commit separates tags into their own package which clearly defines the semantics of tags and provides concrete implementations for them. This simplifies the code considerably, and also more clearly communicates what tags are for. The third attempt to reimplement resource on top of the new primitives worked beautifully. It supports `ResourceList`, but where the previous implementation worked by implicitly adopting resources across runs, the new implementation of `ResourceList` manages the lifetimes of its child resources explicitly. The code is nearly as compact, in part because the new resource implementation is more honest about separating entire-resource state from per-run state. The new resource primitive adds support for resource metadata (state that lives for the entire lifetime of the resource and can be used for cross-run state). --- Co-authored-by: NullVoxPopuli <[email protected]>
- Loading branch information
Showing
51 changed files
with
2,852 additions
and
1,178 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -26,6 +26,6 @@ | |
"test:types": "tsc -b" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "18.16.1" | ||
"@types/node": "18.16.18" | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 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 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,77 @@ | ||
// @vitest-environment jsdom | ||
|
||
import { install, setup } from "@starbeam/preact"; | ||
import { Cell } from "@starbeam/universal"; | ||
import { html, rendering } from "@starbeam-workspace/preact-testing-utils"; | ||
import { describe } from "@starbeam-workspace/test-utils"; | ||
import { options } from "preact"; | ||
import { beforeAll } from "vitest"; | ||
|
||
let nextId = 0; | ||
|
||
describe("create", () => { | ||
beforeAll(() => { | ||
install(options); | ||
}); | ||
|
||
rendering.test( | ||
"baseline", | ||
function App({ name }: { name: string }) { | ||
return html`<div>hello ${name}</div>`; | ||
}, | ||
(render) => | ||
render | ||
.expect(({ name }) => html`<div>hello ${name}</div>`) | ||
.render({ name: "world" }) | ||
); | ||
|
||
rendering.test( | ||
"reactive values render", | ||
function App() { | ||
const { cell } = setup(ReactiveObject); | ||
|
||
return html`<p>${cell.current}</p>`; | ||
}, | ||
(render) => | ||
render | ||
.expect(({ count }: { count: number }) => html`<p>${count}</p>`) | ||
.render({ count: 0 }) | ||
); | ||
|
||
rendering.test( | ||
"reactive values update", | ||
function App() { | ||
const { cell, increment } = setup(ReactiveObject); | ||
|
||
return html`<p>${cell}</p> | ||
<button onClick=${increment}>++</button>`; | ||
}, | ||
(render) => | ||
render | ||
.expect( | ||
({ count }: { count: number }) => | ||
html`<p>${count}</p> | ||
<button>++</button>` | ||
) | ||
.render({ count: 0 }) | ||
.update( | ||
{ count: 1 }, | ||
{ before: async (prev) => prev.find("button").fire.click() } | ||
) | ||
); | ||
}); | ||
|
||
const INITIAL_COUNT = 0; | ||
const INCREMENT = 1; | ||
|
||
function ReactiveObject(): { cell: Cell<number>; increment: () => void } { | ||
const cell = Cell(INITIAL_COUNT, { | ||
description: `ReactiveObject #${++nextId}`, | ||
}); | ||
|
||
function increment(): void { | ||
cell.set(cell.current + INCREMENT); | ||
} | ||
|
||
return { cell, increment }; | ||
} |
This file contains 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 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
Oops, something went wrong.