0.1.3 #4
@@ -9,7 +9,7 @@ import * as React from "react"
|
|||||||
|
|
||||||
|
|
||||||
// Generator version
|
// Generator version
|
||||||
const RouteComponent = Component.make(function* AsyncRendering() {
|
const RouteComponent = Component.make(Effect.fnUntraced(function* AsyncRendering() {
|
||||||
const MemoizedAsyncComponentFC = yield* MemoizedAsyncComponent
|
const MemoizedAsyncComponentFC = yield* MemoizedAsyncComponent
|
||||||
const AsyncComponentFC = yield* AsyncComponent
|
const AsyncComponentFC = yield* AsyncComponent
|
||||||
const [input, setInput] = React.useState("")
|
const [input, setInput] = React.useState("")
|
||||||
@@ -25,7 +25,7 @@ const RouteComponent = Component.make(function* AsyncRendering() {
|
|||||||
<AsyncComponentFC />
|
<AsyncComponentFC />
|
||||||
</Flex>
|
</Flex>
|
||||||
)
|
)
|
||||||
}).pipe(
|
})).pipe(
|
||||||
Component.withRuntime(runtime.context)
|
Component.withRuntime(runtime.context)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ const RouteComponent = Component.make(function* AsyncRendering() {
|
|||||||
// )
|
// )
|
||||||
|
|
||||||
|
|
||||||
class AsyncComponent extends Component.make(function* AsyncComponent() {
|
class AsyncComponent extends Component.make(Effect.fnUntraced(function* AsyncComponent() {
|
||||||
const SubComponentFC = yield* SubComponent
|
const SubComponentFC = yield* SubComponent
|
||||||
|
|
||||||
yield* Effect.sleep("500 millis") // Async operation
|
yield* Effect.sleep("500 millis") // Async operation
|
||||||
@@ -63,16 +63,16 @@ class AsyncComponent extends Component.make(function* AsyncComponent() {
|
|||||||
<SubComponentFC />
|
<SubComponentFC />
|
||||||
</Flex>
|
</Flex>
|
||||||
)
|
)
|
||||||
}).pipe(
|
})).pipe(
|
||||||
Suspense.suspense,
|
Suspense.suspense,
|
||||||
Suspense.withOptions({ defaultFallback: <p>Loading...</p> }),
|
Suspense.withOptions({ defaultFallback: <p>Loading...</p> }),
|
||||||
) {}
|
) {}
|
||||||
class MemoizedAsyncComponent extends Memoized.memo(AsyncComponent) {}
|
class MemoizedAsyncComponent extends Memoized.memo(AsyncComponent) {}
|
||||||
|
|
||||||
class SubComponent extends Component.make(function* SubComponent() {
|
class SubComponent extends Component.make(Effect.fnUntraced(function* SubComponent() {
|
||||||
const [state] = React.useState(yield* Hooks.useOnce(() => Effect.provide(makeUuid4, GetRandomValues.CryptoRandom)))
|
const [state] = React.useState(yield* Hooks.useOnce(() => Effect.provide(makeUuid4, GetRandomValues.CryptoRandom)))
|
||||||
return <Text>{state}</Text>
|
return <Text>{state}</Text>
|
||||||
}) {}
|
})) {}
|
||||||
|
|
||||||
export const Route = createFileRoute("/dev/async-rendering")({
|
export const Route = createFileRoute("/dev/async-rendering")({
|
||||||
component: RouteComponent
|
component: RouteComponent
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { Component, Memoized } from "effect-fc"
|
|||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
|
|
||||||
|
|
||||||
const RouteComponent = Component.make(function* RouteComponent() {
|
const RouteComponent = Component.make(Effect.fnUntraced(function* RouteComponent() {
|
||||||
const [value, setValue] = React.useState("")
|
const [value, setValue] = React.useState("")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -21,14 +21,14 @@ const RouteComponent = Component.make(function* RouteComponent() {
|
|||||||
{yield* Effect.map(MemoizedSubComponent, FC => <FC />)}
|
{yield* Effect.map(MemoizedSubComponent, FC => <FC />)}
|
||||||
</Flex>
|
</Flex>
|
||||||
)
|
)
|
||||||
}).pipe(
|
})).pipe(
|
||||||
Component.withRuntime(runtime.context)
|
Component.withRuntime(runtime.context)
|
||||||
)
|
)
|
||||||
|
|
||||||
class SubComponent extends Component.make(function* SubComponent() {
|
class SubComponent extends Component.make(Effect.fnUntraced(function* SubComponent() {
|
||||||
const id = yield* makeUuid4.pipe(Effect.provide(GetRandomValues.CryptoRandom))
|
const id = yield* makeUuid4.pipe(Effect.provide(GetRandomValues.CryptoRandom))
|
||||||
return <Text>{id}</Text>
|
return <Text>{id}</Text>
|
||||||
}) {}
|
})) {}
|
||||||
|
|
||||||
class MemoizedSubComponent extends Memoized.memo(SubComponent) {}
|
class MemoizedSubComponent extends Memoized.memo(SubComponent) {}
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ import { Hooks } from "effect-fc/hooks"
|
|||||||
const TodosStateLive = TodosState.Default("todos")
|
const TodosStateLive = TodosState.Default("todos")
|
||||||
|
|
||||||
export const Route = createFileRoute("/")({
|
export const Route = createFileRoute("/")({
|
||||||
component: Component.make(function* Index() {
|
component: Component.make(Effect.fnUntraced(function* Index() {
|
||||||
return yield* Todos.pipe(
|
return yield* Todos.pipe(
|
||||||
Effect.map(FC => <FC />),
|
Effect.map(FC => <FC />),
|
||||||
Effect.provide(yield* Hooks.useContext(TodosStateLive, { finalizerExecutionMode: "fork" })),
|
Effect.provide(yield* Hooks.useContext(TodosStateLive, { finalizerExecutionMode: "fork" })),
|
||||||
)
|
)
|
||||||
}).pipe(
|
})).pipe(
|
||||||
Component.withRuntime(runtime.context)
|
Component.withRuntime(runtime.context)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export type TodoProps = (
|
|||||||
| { readonly _tag: "edit", readonly index: number }
|
| { readonly _tag: "edit", readonly index: number }
|
||||||
)
|
)
|
||||||
|
|
||||||
export class Todo extends Component.make(function* Todo(props: TodoProps) {
|
export class Todo extends Component.make(Effect.fnUntraced(function* Todo(props: TodoProps) {
|
||||||
const runtime = yield* Effect.runtime()
|
const runtime = yield* Effect.runtime()
|
||||||
const state = yield* TodosState
|
const state = yield* TodosState
|
||||||
|
|
||||||
@@ -122,6 +122,6 @@ export class Todo extends Component.make(function* Todo(props: TodoProps) {
|
|||||||
}
|
}
|
||||||
</Flex>
|
</Flex>
|
||||||
)
|
)
|
||||||
}).pipe(
|
})).pipe(
|
||||||
Memoized.memo
|
Memoized.memo
|
||||||
) {}
|
) {}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Todo } from "./Todo"
|
|||||||
import { TodosState } from "./TodosState.service"
|
import { TodosState } from "./TodosState.service"
|
||||||
|
|
||||||
|
|
||||||
export class Todos extends Component.make(function* Todos() {
|
export class Todos extends Component.make(Effect.fnUntraced(function* Todos() {
|
||||||
const state = yield* TodosState
|
const state = yield* TodosState
|
||||||
const [todos] = yield* Hooks.useSubscribeRefs(state.ref)
|
const [todos] = yield* Hooks.useSubscribeRefs(state.ref)
|
||||||
|
|
||||||
@@ -30,4 +30,4 @@ export class Todos extends Component.make(function* Todos() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
</Container>
|
</Container>
|
||||||
)
|
)
|
||||||
}) {}
|
})) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user