Skip to content

add RuntimeContext module #12

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
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

tim-smart
Copy link
Collaborator

No description provided.

@@ -23,6 +23,7 @@
"noUnusedLocals": true,
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"jsx": "react",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use "preserve" since it's expected to go through bundling.
Otherwise it's better to use "react-jsx" since it's more compatible with non-react jsx (unintuitively)
Though all-in-all. We don't have any jsx in the project so we can remove this altogether

Comment on lines +30 to +35
export interface RuntimeContext<R> extends ReactContext<R> {
readonly [RuntimeContextTypeId]: {
readonly scope: Scope.CloseableScope
readonly context: Effect.Effect<never, never, Context.Context<R>>
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we want to ride the ReactContext like that. It's mostly likely safe, but it's an eye raising pattern 🤔

Effect.cached,
Effect.runSync
)
Effect.runFork(runtime) // prime cache
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will very likely break in ssr environments 🤔

Comment on lines +38 to +41
const resultBag = useSyncExternalStore(
storeRef.current.subscribe,
storeRef.current.snapshot
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3rd argument for SSR. Maybe just return a static Initial until we figure out the serverside?

@@ -21,6 +23,19 @@ describe("useResult", () => {
expect(Result.isSuccess(result.current.result)).toBe(true)
})

it("override Provider value", async () => {
const [Override] = RuntimeContext.overrideLayer(context, Layer.succeed(foo, { value: 2 }))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern feels "unnatural" in react settings. We need to think if we want to do this or something else..

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.

2 participants