Skip to content

Commit

Permalink
refactor: revert attach
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Feb 12, 2024
1 parent 5acc9e2 commit e000a06
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
2 changes: 1 addition & 1 deletion examples/_dev/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ app.frame('/falsy-intents', () => {
}
})

app.attach(todoApp)
app.route('/todos', todoApp)

const server = Bun.serve(app)
console.log(`𝑭𝒂𝒓𝒄 ▶︎ http://localhost:${server.port}/dev`)
1 change: 0 additions & 1 deletion examples/_dev/src/todos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const app = new Farc<State>({
index: -1,
todos: [],
},
route: '/todos',
})

app.frame('/', ({ buttonValue, deriveState, inputText }) => {
Expand Down
30 changes: 2 additions & 28 deletions src/farc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import { ImageResponse } from 'hono-og'
import { inspectRoutes } from 'hono/dev'
import type { HonoOptions } from 'hono/hono-base'
import { jsxRenderer } from 'hono/jsx-renderer'
import {
type Env,
type MergePath,
type MergeSchemaPath,
type Schema,
} from 'hono/types'
import { type Env, type Schema } from 'hono/types'

import { App, DevStyles, Preview } from './dev/components.js'
import { getFrameRoutes, htmlToFrame, htmlToState } from './dev/utils.js'
Expand All @@ -39,7 +34,6 @@ export type FarcConstructorParameters<
env extends Env = Env,
> = HonoOptions<env> & {
initialState?: state | undefined
route?: string | undefined
}

export type FrameHandlerReturnType = {
Expand All @@ -56,31 +50,13 @@ export class Farc<
basePath extends string = '/',
> extends Hono<env, schema, basePath> {
#initialState: state = undefined as state
subPath: string | undefined

constructor({
initialState,
route,
...options
}: FarcConstructorParameters<state, env> = {}) {
super(options)
if (initialState) this.#initialState = initialState
if (route) this.subPath = route
}

attach<
subEnv extends Env,
subSchema extends Schema,
subBasePath extends string,
>(
app: Farc<any, subEnv, subSchema, subBasePath>,
): Farc<
any,
env,
MergeSchemaPath<subSchema, MergePath<basePath, subBasePath>> & schema,
basePath
> {
return this.route(app.subPath!, app as any) as any
}

frame<path extends string>(
Expand Down Expand Up @@ -152,9 +128,7 @@ export class Farc<
property="fc:frame:post_url"
content={`${
action
? toBaseUrl(c.req.url) +
parsePath(this.subPath || '') +
parsePath(action || '')
? toBaseUrl(c.req.url) + parsePath(action || '')
: context.url
}?${postSearch}`}
/>
Expand Down

0 comments on commit e000a06

Please sign in to comment.