Skip to content

Commit da29174

Browse files
committed
fix: ESLint errors - remove this aliasing and unused import
1 parent caa0d75 commit da29174

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

packages/feathers/src/hooks.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,9 @@ export function hookMixin<A>(this: A, service: FeathersService<A>, path: string,
192192
return service
193193
}
194194

195-
const app = this
196195
const hookMethods = getHookMethods(service, options)
197196

198-
const createMethodHookManager = (method: string) => {
197+
const createMethodHookManager = (app: A, method: string) => {
199198
const params = (defaultServiceArguments as any)[method] || ['data', 'params']
200199

201200
return new FeathersHookManager<A>(app, method).params(...params).props({
@@ -216,7 +215,7 @@ export function hookMixin<A>(this: A, service: FeathersService<A>, path: string,
216215
}
217216

218217
const serviceMethodHooks = hookMethods.reduce((res, method) => {
219-
res[method] = createMethodHookManager(method)
218+
res[method] = createMethodHookManager(this, method)
220219
return res
221220
}, {} as BaseHookMap)
222221

@@ -227,7 +226,18 @@ export function hookMixin<A>(this: A, service: FeathersService<A>, path: string,
227226

228227
hooks(service, serviceMethodHooks)
229228

230-
service.hooks = function (this: any, hookOptions: any) {
229+
service.hooks = createServiceHooksMethod(this, service, registerHooks, createMethodHookManager)
230+
231+
return service
232+
}
233+
234+
function createServiceHooksMethod<A>(
235+
app: A,
236+
service: FeathersService<A>,
237+
registerHooks: ReturnType<typeof enableHooks>,
238+
createMethodHookManager: (app: A, method: string) => FeathersHookManager<A>
239+
) {
240+
return function (this: any, hookOptions: any) {
231241
if (hookOptions.before || hookOptions.after || hookOptions.error || hookOptions.around) {
232242
return registerHooks.call(this, hookOptions)
233243
}
@@ -250,7 +260,7 @@ export function hookMixin<A>(this: A, service: FeathersService<A>, path: string,
250260
throw new Error(`Method ${method} does not exist on this service`)
251261
}
252262

253-
const methodManager = createMethodHookManager(method)
263+
const methodManager = createMethodHookManager(app, method)
254264
hooks(this, { [method]: methodManager })
255265
manager = methodManager
256266
}
@@ -260,6 +270,4 @@ export function hookMixin<A>(this: A, service: FeathersService<A>, path: string,
260270

261271
return this
262272
}
263-
264-
return service
265273
}

packages/feathers/src/http/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createServer } from 'node:http'
33
import { restTests, verify, getApp, createTestServer } from '../../fixtures/index.js'
44
import { CORS_HEADERS, createHandler } from './index.js'
55
import { toNodeHandler } from './node.js'
6-
import { feathers, Params } from '../index.js'
6+
import { feathers } from '../index.js'
77

88
const TEST_PORT = 4444
99
const EXTERNAL_METHODS_PORT = 4445

0 commit comments

Comments
 (0)