From 12a7d704ee33dfa3c2d0125cfa8c44e5b1414729 Mon Sep 17 00:00:00 2001 From: dk <2597375+Thesephi@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:22:00 +0200 Subject: [PATCH 1/2] attempt to retain 'this' as much as possible --- CHANGELOG.md | 4 ++++ jsr.json | 2 +- src/ControllerMethodArgs.ts | 2 +- src/useOakServer.ts | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55e6ade..6d91b2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [Unrelease] + +- `this` is retained when invoking controller methods + ## [0.8.7] - 2024-07-15 ### Changed diff --git a/jsr.json b/jsr.json index 6f366a8..bf6ea97 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,6 @@ { "name": "@dklab/oak-routing-ctrl", - "version": "0.8.7", + "version": "0.9.0-alpha.1", "exports": { ".": "./mod.ts", "./mod": "./mod.ts" diff --git a/src/ControllerMethodArgs.ts b/src/ControllerMethodArgs.ts index 7136c4f..160899c 100644 --- a/src/ControllerMethodArgs.ts +++ b/src/ControllerMethodArgs.ts @@ -183,7 +183,7 @@ function getEnhancedHandler( decoratedArgs.push(ctx); return await consumerSuppliedHandler.call( - consumerSuppliedHandler, + this, ...decoratedArgs, ); } diff --git a/src/useOakServer.ts b/src/useOakServer.ts index 44a8a1b..c8a429e 100644 --- a/src/useOakServer.ts +++ b/src/useOakServer.ts @@ -14,7 +14,7 @@ export const useOakServer = ( Controllers: ControllerClass[], ): void => { for (const Ctrl of Controllers) { - new Ctrl(); + const ctrl: unknown = new Ctrl(); const ctrlProps: string[] = Object.getOwnPropertyNames(Ctrl.prototype); for (const propName of ctrlProps) { if (propName === "constructor") continue; @@ -28,7 +28,7 @@ export const useOakServer = ( Ctrl.prototype, propName, )?.value; - const handlerRetVal = await handler(ctx); + const handlerRetVal = await handler.call(ctrl, ctx); // some developers set body within the handler, // some developers return something from the handler // and expect that it gets assigned to the response, From cbf23e9976ce8567d467047194099741f81cbcce Mon Sep 17 00:00:00 2001 From: dk <2597375+Thesephi@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:24:23 +0200 Subject: [PATCH 2/2] Release/0.9.0 --- CHANGELOG.md | 5 ++++- jsr.json | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d91b2a..48a6abd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ -## [Unrelease] +## [0.9.0] - 2024-07-16 + +### Changed - `this` is retained when invoking controller methods +- `./test_utils` excluded from dist package ## [0.8.7] - 2024-07-15 diff --git a/jsr.json b/jsr.json index bf6ea97..030f042 100644 --- a/jsr.json +++ b/jsr.json @@ -1,12 +1,12 @@ { "name": "@dklab/oak-routing-ctrl", - "version": "0.9.0-alpha.1", + "version": "0.9.0", "exports": { ".": "./mod.ts", "./mod": "./mod.ts" }, "exclude": [ - "./src/test_utils", + "./test_utils", "**/*_test.ts", "cov_profile", "cov_profile.lcov",