Skip to content
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

Resource Reform #112

Merged
merged 50 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0f8d0c4
@starbeam/shared lifetime
wycats Jun 22, 2023
3ef7ea3
checkpoint
wycats Jun 29, 2023
364c021
Checkpoint
wycats Jul 26, 2023
757c52a
Finish Sync and implement Resource
wycats Jul 31, 2023
a55aba3
Most of Resource Reform is done
wycats Aug 2, 2023
c047a80
Improvements to Sync children
wycats Aug 5, 2023
95f5fd8
Fix lifetime impl in @starbeam/shared
wycats Aug 7, 2023
0484117
Child resources apparently work
wycats Aug 8, 2023
aed302f
Fix finalization tests
wycats Aug 8, 2023
0cb97fe
Implement ResourceList
wycats Aug 9, 2023
7a93358
A better-rationalized ResourceList
wycats Aug 10, 2023
75b4447
Add getServiceFormula
wycats Sep 4, 2023
3ef4242
Build success
NullVoxPopuli Sep 5, 2023
921ceb7
reduceLock
NullVoxPopuli Sep 5, 2023
fa22db4
Preact is passing
wycats Sep 5, 2023
470e4d9
Get rid of old infra + vue works
wycats Sep 6, 2023
74d62bd
Vue mostly done
wycats Sep 6, 2023
45afa19
Clean up vue
wycats Sep 7, 2023
2b13f8f
@starbeam/shared lifetime
wycats Jun 22, 2023
e8d8a71
checkpoint
wycats Jun 29, 2023
4289432
Checkpoint
wycats Jul 26, 2023
acf2b14
Finish Sync and implement Resource
wycats Jul 31, 2023
2b99e01
Most of Resource Reform is done
wycats Aug 2, 2023
31aa2d8
Improvements to Sync children
wycats Aug 5, 2023
e02de38
Fix lifetime impl in @starbeam/shared
wycats Aug 7, 2023
c713304
Child resources apparently work
wycats Aug 8, 2023
98dd7ff
Fix finalization tests
wycats Aug 8, 2023
822c461
Implement ResourceList
wycats Aug 9, 2023
ba48779
A better-rationalized ResourceList
wycats Aug 10, 2023
6ddf44d
Add getServiceFormula
wycats Sep 4, 2023
64d19bd
Build success
NullVoxPopuli Sep 5, 2023
81dafab
reduceLock
NullVoxPopuli Sep 5, 2023
fed665a
Preact is passing
wycats Sep 5, 2023
38247f2
Get rid of old infra + vue works
wycats Sep 6, 2023
9da5b14
Vue mostly done
wycats Sep 6, 2023
8c19ea3
Clean up vue
wycats Sep 7, 2023
71012f2
Merge remote-tracking branch 'origin/feature/resources-refresh' into …
wycats Sep 18, 2023
d4fcaff
React passes
wycats Sep 18, 2023
aea6b6b
Update checkpoint
wycats Sep 18, 2023
c5b5964
Lints work
wycats Sep 19, 2023
ebb36e3
Update test packages
wycats Sep 20, 2023
fdb9f52
Update lockfile
wycats Sep 20, 2023
4c1252d
Update build
wycats Sep 20, 2023
42b4e7b
Remove errant .only
wycats Sep 20, 2023
d13c0d8
Run CI specs using vitest workspace
wycats Sep 20, 2023
5542deb
More lint work
wycats Sep 21, 2023
dc3844f
Disable react tests in prod environment
wycats Sep 22, 2023
6f83b5f
Clean up more lints.
wycats Sep 22, 2023
a2d113b
Fix type error
wycats Sep 22, 2023
48235ea
Remove duplicate (and broken) test
wycats Sep 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Checkpoint
  • Loading branch information
wycats authored and NullVoxPopuli committed Sep 5, 2023
commit 364c0215b7cced0713b4cfab0dd2b731d54da2b9
16 changes: 0 additions & 16 deletions .devcontainer/Dockerfile

This file was deleted.

34 changes: 0 additions & 34 deletions .devcontainer/devcontainer.json

This file was deleted.

3 changes: 0 additions & 3 deletions .devcontainer/scripts/on-create.sh

This file was deleted.

3 changes: 0 additions & 3 deletions .devcontainer/scripts/post-start.sh

This file was deleted.

4 changes: 0 additions & 4 deletions .devcontainer/scripts/update-content.sh

This file was deleted.

6 changes: 3 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"recommendations": [
"foxundermoon.shell-format",
"rohit-gohri.format-code-action",
"ghmcadams.lintlens",
"wayou.vscode-todo-highlight",
"gruntfuggly.todo-tree"
"gruntfuggly.todo-tree",
"esbenp.prettier-vscode",
"mskelton.npm-outdated"
]
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"pnpm-lock.yaml": true
},

"testing.automaticallyOpenPeekView": "never",
// Try to avoid auto-importing other packages in the mono-repo as relative
// paths. Instead, use the packaage name.
"typescript.preferences.importModuleSpecifier": "project-relative",
Expand Down
17 changes: 17 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
{
"tasks": [
{
"label": "versionlens npm install",
"command": "pnpm",
"type": "shell",
"args": ["install"],
"options": {
// sets the cwd to the current file dir
"cwd": "${fileDirname}"
},
// customizable settings
"presentation": {
"echo": true,
"reveal": "always",
"panel": "shared",
"clear": true,
},
},
{
"args": ["test:workspace:types"],
"command": "pnpm",
Expand Down
53 changes: 27 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,46 @@
"@starbeam/core-utils": "workspace:^"
},
"devDependencies": {
"@babel/eslint-parser": "^7.22.5",
"@babel/plugin-proposal-decorators": "^7.22.5",
"@babel/eslint-parser": "^7.22.9",
"@babel/plugin-proposal-decorators": "^7.22.7",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.22.5",
"@babel/preset-env": "^7.22.5",
"@babel/plugin-transform-runtime": "^7.22.9",
"@babel/preset-env": "^7.22.9",
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@babel/runtime": "^7.22.5",
"@babel/runtime": "^7.22.6",
"@changesets/changelog-git": "^0.1.14",
"@changesets/cli": "^2.26.1",
"@changesets/config": "^2.3.0",
"@changesets/cli": "^2.26.2",
"@changesets/config": "^2.3.1",
"@nrr/pnpm-duplicate-cli": "^0.0.1",
"@starbeam/eslint-plugin": "workspace:^",
"@starbeam-dev/build-support": "workspace:*",
"@types/eslint": "^8.40.2",
"@types/node": "20.3.1",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"@vitest/ui": "^0.32.2",
"eslint": "^8.43.0",
"@types/eslint": "^8.44.1",
"@types/node": "20.4.5",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"@vitest/ui": "^0.33.0",
"eslint": "^8.45.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.8.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsonc": "^2.9.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"esno": "^0.16.3",
"fast-glob": "^3.2.12",
"happy-dom": "^9.20.3",
"eslint-plugin-unused-imports": "^3.0.0",
"esno": "^0.17.0",
"fast-glob": "^3.3.1",
"happy-dom": "^10.5.2",
"jsdom": "^22.1.0",
"prettier": "^2.8.8",
"rollup": "^3.25.3",
"tslib": "^2.5.3",
"turbo": "^1.10.6",
"typescript": "^5.1.3",
"vite": "4.3.9",
"prettier": "^3.0.0",
"rollup": "^3.26.3",
"tslib": "^2.6.1",
"turbo": "^1.10.12",
"typescript": "^5.1.6",
"vite": "4.4.7",
"vite-plugin-babel": "^1.1.3",
"vitest": "^0.32.2"
"vitest": "^0.33.0"
},
"license": "MIT",
"nodemonConfig": {
Expand Down Expand Up @@ -179,12 +179,13 @@
"vue"
],
"allowedVersions": {
"@typescript-eslint/eslint-plugin": "6",
"typescript": "*"
}
}
},
"volta": {
"node": "20.3.1",
"pnpm": "8.6.3"
"pnpm": "8.6.10"
}
}
1 change: 1 addition & 0 deletions packages/preact/preact/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export {
useResource,
useService,
} from "./src/resource.js";
export { setupSync } from "./src/sync.js";
3 changes: 2 additions & 1 deletion packages/preact/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"test:types": "tsc -b"
},
"dependencies": {
"@preact/signals": "^1.1.3",
"@preact/signals": "^1.1.5",
"@starbeam/core-utils": "workspace:^",
"@starbeam/debug": "workspace:^",
"@starbeam/interfaces": "workspace:^",
Expand All @@ -41,6 +41,7 @@
"@starbeam/resource": "workspace:^",
"@starbeam/runtime": "workspace:^",
"@starbeam/service": "workspace:^",
"@starbeam/shared": "workspace:^",
"@starbeam/tags": "workspace:^",
"@starbeam/universal": "workspace:^",
"@starbeam/verify": "workspace:^"
Expand Down
24 changes: 12 additions & 12 deletions packages/preact/preact/src/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ import { initializeFormulaTag } from "@starbeam/tags";
import { expected, isPresent, verify } from "@starbeam/verify";

export class ComponentFrame {
#active: InitializingFormula | null;
#frame: FinalizedFormula | null;
#tag: FormulaTag;
#subscription: Unsubscribe | null;

static #frames = new WeakMap<InternalComponent, ComponentFrame>();
static #stack: InternalComponent[] = [];

static start(
component: InternalComponent,
description: Description | undefined
description: Description | undefined,
): void {
let frame = ComponentFrame.#frames.get(component);

Expand All @@ -45,22 +40,22 @@ export class ComponentFrame {
const current = getLast(ComponentFrame.#stack);
if (!current) {
throw Error(
"You are attempting to use a feature of Starbeam that depends on the current component, but no component is currently active."
"You are attempting to use a feature of Starbeam that depends on the current component, but no component is currently active.",
);
}
return current;
}

static end(
component: InternalComponent,
subscription?: () => void
subscription?: () => void,
): FinalizedFormula {
const frame = ComponentFrame.#frames.get(component);

verify(
frame,
isPresent,
expected.when("in Preact's _diff hook").as("a tracking frame")
expected.when("in Preact's _diff hook").as("a tracking frame"),
);

const end = frame.#end(subscription);
Expand All @@ -76,17 +71,22 @@ export class ComponentFrame {
}
}

#active: InitializingFormula | null;
#frame: FinalizedFormula | null;
#tag: FormulaTag;
#subscription: Unsubscribe | null;

private constructor(
frame: FinalizedFormula | null,
active: InitializingFormula | null,
subscribed: Unsubscribe | null,
description: Description | undefined
description: Description | undefined,
) {
this.#frame = frame;
this.#active = active;
const tag = initializeFormulaTag(
DEBUG?.Desc("formula", description),
() => this.#frame?.children() ?? new Set()
() => this.#frame?.children() ?? new Set(),
);
this.#tag = tag;
this.#subscription = subscribed;
Expand All @@ -105,7 +105,7 @@ export class ComponentFrame {
verify(
this.#active,
isPresent,
expected.when("in preact's _diff hook").as("an active tracking frame")
expected.when("in preact's _diff hook").as("an active tracking frame"),
);

const frame = (this.#frame = this.#active.done());
Expand Down
9 changes: 5 additions & 4 deletions packages/preact/preact/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type {
} from "@starbeam/preact-utils";
import { Plugin } from "@starbeam/preact-utils";
import { DEBUG, isReactive } from "@starbeam/reactive";
import { CONTEXT, RUNTIME } from "@starbeam/runtime";
import { CONTEXT } from "@starbeam/runtime";
import { finalize } from "@starbeam/shared";
import type { ComponentType } from "preact";

import { ComponentFrame } from "./frame.js";
Expand Down Expand Up @@ -43,8 +44,8 @@ export const install = Plugin((on) => {
DEBUG?.Desc(
"formula",
componentName(component.fn),
"preact.componentWillRender"
)
"preact.componentWillRender",
),
);
});

Expand All @@ -66,7 +67,7 @@ export const install = Plugin((on) => {

on.component.unmount((component) => {
ComponentFrame.unmount(component);
RUNTIME.finalize(component);
finalize(component);
});
});

Expand Down
36 changes: 36 additions & 0 deletions packages/preact/preact/src/sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Unsubscribe } from "@starbeam/interfaces";
import type { Sync } from "@starbeam/resource";
import { RUNTIME } from "@starbeam/runtime";
import { onFinalize } from "@starbeam/shared";
import { useEffect, useMemo, useRef, useState } from "preact/hooks";

import { getCurrentComponent } from "./options.js";

export function setupSync(sync: Sync): void {
const [notify, setNotify] = useState({});
const activeSync = useMemo(() => {
return sync(getCurrentComponent());
}, []);
const unsubscribe = useRef(null as null | Unsubscribe);
const component = getCurrentComponent();

useEffect(() => {
if (unsubscribe.current === null) {
onFinalize(component, () => {
console.log("HI");
});

const activeSync = sync(component);
unsubscribe.current = RUNTIME.subscribe(
activeSync,
() => void setNotify({}),
);
}

activeSync();

return () => {
unsubscribe.current?.();
};
}, [notify]);
}
Loading