@@ -2,7 +2,8 @@ import * as Domain from "@/domain"
|
||||
import { Box, Button, Flex, IconButton, TextArea } from "@radix-ui/themes"
|
||||
import { GetRandomValues, makeUuid4 } from "@typed/id"
|
||||
import { Chunk, Effect, Match, Option, Ref, Runtime, SubscriptionRef } from "effect"
|
||||
import { Component, Hook, Memoized } from "effect-fc"
|
||||
import { Component, Memoized } from "effect-fc"
|
||||
import { Hooks } from "effect-fc/hooks"
|
||||
import { SubscriptionSubRef } from "effect-fc/types"
|
||||
import { FaArrowDown, FaArrowUp } from "react-icons/fa"
|
||||
import { FaDeleteLeft } from "react-icons/fa6"
|
||||
@@ -28,7 +29,7 @@ export class Todo extends Component.make(function* Todo(props: TodoProps) {
|
||||
const runtime = yield* Effect.runtime()
|
||||
const state = yield* TodosState
|
||||
|
||||
const [ref, contentRef] = yield* Hook.useMemo(() => Match.value(props).pipe(
|
||||
const [ref, contentRef] = yield* Hooks.useMemo(() => Match.value(props).pipe(
|
||||
Match.tag("new", () => Effect.andThen(makeTodo, SubscriptionRef.make)),
|
||||
Match.tag("edit", ({ index }) => Effect.succeed(SubscriptionSubRef.makeFromChunkRef(state.ref, index))),
|
||||
Match.exhaustive,
|
||||
@@ -39,7 +40,7 @@ export class Todo extends Component.make(function* Todo(props: TodoProps) {
|
||||
] as const),
|
||||
), [props._tag, props.index])
|
||||
|
||||
const [content, size] = yield* Hook.useSubscribeRefs(contentRef, state.sizeRef)
|
||||
const [content, size] = yield* Hooks.useSubscribeRefs(contentRef, state.sizeRef)
|
||||
|
||||
return (
|
||||
<Flex direction="column" align="stretch" gap="2">
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { Container, Flex, Heading } from "@radix-ui/themes"
|
||||
import { Chunk, Console, Effect } from "effect"
|
||||
import { Component, Hook } from "effect-fc"
|
||||
import { Component } from "effect-fc"
|
||||
import { Hooks } from "effect-fc/hooks"
|
||||
import { Todo } from "./Todo"
|
||||
import { TodosState } from "./TodosState.service"
|
||||
|
||||
|
||||
export class Todos extends Component.make(function* Todos() {
|
||||
const state = yield* TodosState
|
||||
const [todos] = yield* Hook.useSubscribeRefs(state.ref)
|
||||
const [todos] = yield* Hooks.useSubscribeRefs(state.ref)
|
||||
|
||||
yield* Hook.useOnce(() => Effect.andThen(
|
||||
yield* Hooks.useOnce(() => Effect.andThen(
|
||||
Console.log("Todos mounted"),
|
||||
Effect.addFinalizer(() => Console.log("Todos unmounted")),
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user