@@ -11,15 +11,15 @@
|
|||||||
// Import Routes
|
// Import Routes
|
||||||
|
|
||||||
import { Route as rootRoute } from './routes/__root'
|
import { Route as rootRoute } from './routes/__root'
|
||||||
import { Route as TeardownImport } from './routes/teardown'
|
import { Route as TimeImport } from './routes/time'
|
||||||
import { Route as CountImport } from './routes/count'
|
import { Route as CountImport } from './routes/count'
|
||||||
import { Route as IndexImport } from './routes/index'
|
import { Route as IndexImport } from './routes/index'
|
||||||
|
|
||||||
// Create/Update Routes
|
// Create/Update Routes
|
||||||
|
|
||||||
const TeardownRoute = TeardownImport.update({
|
const TimeRoute = TimeImport.update({
|
||||||
id: '/teardown',
|
id: '/time',
|
||||||
path: '/teardown',
|
path: '/time',
|
||||||
getParentRoute: () => rootRoute,
|
getParentRoute: () => rootRoute,
|
||||||
} as any)
|
} as any)
|
||||||
|
|
||||||
@@ -53,11 +53,11 @@ declare module '@tanstack/react-router' {
|
|||||||
preLoaderRoute: typeof CountImport
|
preLoaderRoute: typeof CountImport
|
||||||
parentRoute: typeof rootRoute
|
parentRoute: typeof rootRoute
|
||||||
}
|
}
|
||||||
'/teardown': {
|
'/time': {
|
||||||
id: '/teardown'
|
id: '/time'
|
||||||
path: '/teardown'
|
path: '/time'
|
||||||
fullPath: '/teardown'
|
fullPath: '/time'
|
||||||
preLoaderRoute: typeof TeardownImport
|
preLoaderRoute: typeof TimeImport
|
||||||
parentRoute: typeof rootRoute
|
parentRoute: typeof rootRoute
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,41 +68,41 @@ declare module '@tanstack/react-router' {
|
|||||||
export interface FileRoutesByFullPath {
|
export interface FileRoutesByFullPath {
|
||||||
'/': typeof IndexRoute
|
'/': typeof IndexRoute
|
||||||
'/count': typeof CountRoute
|
'/count': typeof CountRoute
|
||||||
'/teardown': typeof TeardownRoute
|
'/time': typeof TimeRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileRoutesByTo {
|
export interface FileRoutesByTo {
|
||||||
'/': typeof IndexRoute
|
'/': typeof IndexRoute
|
||||||
'/count': typeof CountRoute
|
'/count': typeof CountRoute
|
||||||
'/teardown': typeof TeardownRoute
|
'/time': typeof TimeRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileRoutesById {
|
export interface FileRoutesById {
|
||||||
__root__: typeof rootRoute
|
__root__: typeof rootRoute
|
||||||
'/': typeof IndexRoute
|
'/': typeof IndexRoute
|
||||||
'/count': typeof CountRoute
|
'/count': typeof CountRoute
|
||||||
'/teardown': typeof TeardownRoute
|
'/time': typeof TimeRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileRouteTypes {
|
export interface FileRouteTypes {
|
||||||
fileRoutesByFullPath: FileRoutesByFullPath
|
fileRoutesByFullPath: FileRoutesByFullPath
|
||||||
fullPaths: '/' | '/count' | '/teardown'
|
fullPaths: '/' | '/count' | '/time'
|
||||||
fileRoutesByTo: FileRoutesByTo
|
fileRoutesByTo: FileRoutesByTo
|
||||||
to: '/' | '/count' | '/teardown'
|
to: '/' | '/count' | '/time'
|
||||||
id: '__root__' | '/' | '/count' | '/teardown'
|
id: '__root__' | '/' | '/count' | '/time'
|
||||||
fileRoutesById: FileRoutesById
|
fileRoutesById: FileRoutesById
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RootRouteChildren {
|
export interface RootRouteChildren {
|
||||||
IndexRoute: typeof IndexRoute
|
IndexRoute: typeof IndexRoute
|
||||||
CountRoute: typeof CountRoute
|
CountRoute: typeof CountRoute
|
||||||
TeardownRoute: typeof TeardownRoute
|
TimeRoute: typeof TimeRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootRouteChildren: RootRouteChildren = {
|
const rootRouteChildren: RootRouteChildren = {
|
||||||
IndexRoute: IndexRoute,
|
IndexRoute: IndexRoute,
|
||||||
CountRoute: CountRoute,
|
CountRoute: CountRoute,
|
||||||
TeardownRoute: TeardownRoute,
|
TimeRoute: TimeRoute,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const routeTree = rootRoute
|
export const routeTree = rootRoute
|
||||||
@@ -117,7 +117,7 @@ export const routeTree = rootRoute
|
|||||||
"children": [
|
"children": [
|
||||||
"/",
|
"/",
|
||||||
"/count",
|
"/count",
|
||||||
"/teardown"
|
"/time"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/": {
|
"/": {
|
||||||
@@ -126,8 +126,8 @@ export const routeTree = rootRoute
|
|||||||
"/count": {
|
"/count": {
|
||||||
"filePath": "count.tsx"
|
"filePath": "count.tsx"
|
||||||
},
|
},
|
||||||
"/teardown": {
|
"/time": {
|
||||||
"filePath": "teardown.tsx"
|
"filePath": "time.tsx"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ function Root() {
|
|||||||
<Reffuse.Provider>
|
<Reffuse.Provider>
|
||||||
<div className="container mx-auto flex-row justify-center items-center gap-2 mb-4">
|
<div className="container mx-auto flex-row justify-center items-center gap-2 mb-4">
|
||||||
<Link to="/">Index</Link>
|
<Link to="/">Index</Link>
|
||||||
|
<Link to="/time">Time</Link>
|
||||||
<Link to="/count">Count</Link>
|
<Link to="/count">Count</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import { Reffuse } from "@/reffuse"
|
|
||||||
import { createFileRoute } from "@tanstack/react-router"
|
|
||||||
import { DateTime, Effect, Ref, SubscriptionRef } from "effect"
|
|
||||||
import { useMemo } from "react"
|
|
||||||
|
|
||||||
|
|
||||||
export const Route = createFileRoute("/teardown")({
|
|
||||||
component: Teardown
|
|
||||||
})
|
|
||||||
|
|
||||||
function Teardown() {
|
|
||||||
|
|
||||||
const runtime = Reffuse.useRuntime()
|
|
||||||
|
|
||||||
const timeRef = useMemo(() => DateTime.now.pipe(
|
|
||||||
Effect.flatMap(SubscriptionRef.make),
|
|
||||||
runtime.runSync,
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
), [])
|
|
||||||
|
|
||||||
Reffuse.useFork(DateTime.now.pipe(
|
|
||||||
Effect.flatMap(Ref.set(timeRef))
|
|
||||||
))
|
|
||||||
|
|
||||||
const [time] = Reffuse.useRef(timeRef)
|
|
||||||
|
|
||||||
|
|
||||||
return <></>
|
|
||||||
|
|
||||||
}
|
|
||||||
42
packages/example/src/routes/time.tsx
Normal file
42
packages/example/src/routes/time.tsx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { Reffuse } from "@/reffuse"
|
||||||
|
import { createFileRoute } from "@tanstack/react-router"
|
||||||
|
import { Console, DateTime, Effect, Ref, Schedule, SubscriptionRef } from "effect"
|
||||||
|
import { useMemo } from "react"
|
||||||
|
|
||||||
|
|
||||||
|
export const Route = createFileRoute("/time")({
|
||||||
|
component: Time
|
||||||
|
})
|
||||||
|
|
||||||
|
function Time() {
|
||||||
|
|
||||||
|
const runtime = Reffuse.useRuntime()
|
||||||
|
|
||||||
|
const timeRef = useMemo(() => DateTime.now.pipe(
|
||||||
|
Effect.flatMap(SubscriptionRef.make),
|
||||||
|
runtime.runSync,
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
), [])
|
||||||
|
|
||||||
|
Reffuse.useFork(Effect.addFinalizer(() => Console.log("Component unmounted.")).pipe(
|
||||||
|
Effect.flatMap(() => DateTime.now),
|
||||||
|
Effect.flatMap(v => Ref.set(timeRef, v)),
|
||||||
|
Effect.repeat(Schedule.spaced("1 second")),
|
||||||
|
))
|
||||||
|
|
||||||
|
const [time] = Reffuse.useRefState(timeRef)
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="container mx-auto">
|
||||||
|
<p className="text-center">
|
||||||
|
{DateTime.format(time, {
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "numeric",
|
||||||
|
second: "numeric",
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Effect, Exit, Fiber, Layer, ManagedRuntime, Ref, Runtime, Stream, SubscriptionRef } from "effect"
|
import { Effect, Exit, Fiber, Layer, ManagedRuntime, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
|
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ export class Reffuse<R, ER> {
|
|||||||
|
|
||||||
|
|
||||||
useFork<A, E>(
|
useFork<A, E>(
|
||||||
self: Effect.Effect<A, E, R>,
|
self: Effect.Effect<A, E, R | Scope.Scope>,
|
||||||
deps?: React.DependencyList,
|
deps?: React.DependencyList,
|
||||||
options?: Runtime.RunForkOptions,
|
options?: Runtime.RunForkOptions,
|
||||||
): void {
|
): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user