mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-24 06:45:22 +00:00
refactor(question): build httpapi handlers once
Resolve the question service once when constructing the HttpApi group layer and close over the resulting handlers, instead of doing a tag lookup inside each handler invocation.
This commit is contained in:
@@ -50,26 +50,28 @@ const Api = HttpApi.make("question")
|
||||
}),
|
||||
)
|
||||
|
||||
const list = Effect.fn("QuestionHttpApi.list")(function* () {
|
||||
const svc = yield* Question.Service
|
||||
return yield* svc.list()
|
||||
})
|
||||
const QuestionLive = Layer.unwrap(
|
||||
Effect.gen(function* () {
|
||||
const svc = yield* Question.Service
|
||||
|
||||
const reply = Effect.fn("QuestionHttpApi.reply")(function* (ctx: {
|
||||
params: { requestID: QuestionID }
|
||||
payload: Question.Reply
|
||||
}) {
|
||||
const svc = yield* Question.Service
|
||||
yield* svc.reply({
|
||||
requestID: ctx.params.requestID,
|
||||
answers: ctx.payload.answers,
|
||||
})
|
||||
return true
|
||||
})
|
||||
const list = Effect.fn("QuestionHttpApi.list")(function* () {
|
||||
return yield* svc.list()
|
||||
})
|
||||
|
||||
const QuestionLive = HttpApiBuilder.group(Api, "question", (handlers) =>
|
||||
handlers.handle("list", list).handle("reply", reply),
|
||||
)
|
||||
const reply = Effect.fn("QuestionHttpApi.reply")(function* (ctx: {
|
||||
params: { requestID: QuestionID }
|
||||
payload: Question.Reply
|
||||
}) {
|
||||
yield* svc.reply({
|
||||
requestID: ctx.params.requestID,
|
||||
answers: ctx.payload.answers,
|
||||
})
|
||||
return true
|
||||
})
|
||||
|
||||
return HttpApiBuilder.group(Api, "question", (handlers) => handlers.handle("list", list).handle("reply", reply))
|
||||
}),
|
||||
).pipe(Layer.provide(Question.defaultLayer))
|
||||
|
||||
const web = lazy(() =>
|
||||
HttpRouter.toWebHandler(
|
||||
|
||||
Reference in New Issue
Block a user