Skip to content

Commit

Permalink
refactor: env in handler factory
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Jan 28, 2025
1 parent e3377e6 commit 7aa216f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-plants-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/core": patch
---

`KopflosEnvironment` is also added as `this` context of handler factory
6 changes: 3 additions & 3 deletions packages/core/lib/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface ObjectHandler {

export type Handler = SubjectHandler | ObjectHandler

type HandlerFactory = (...args: unknown[]) => Handler | Promise<Handler>
type HandlerFactory = (this: KopflosEnvironment, ...args: unknown[]) => Handler | Promise<Handler>

export interface HandlerLookup {
(match: ResourceShapeMatch, method: HttpMethod, kopflos: Kopflos): Array<Promise<Handler> | Handler>
Expand Down Expand Up @@ -100,10 +100,10 @@ function createHandlerFactory(env: KopflosEnvironment, variables: Map<string, un
variables,
...env.load.options,
})
return factory?.(...args)
return factory?.call(env, ...args)
}

return factory?.()
return factory?.call(env)
})
}
}
Expand Down

0 comments on commit 7aa216f

Please sign in to comment.