fix: avoid find calls

old-agentic-v1^2
Philipp Burckhardt 2023-06-21 16:48:33 -04:00
rodzic 809a5d4484
commit b475ea87a1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: A2C3BCA4F31D1DDD
1 zmienionych plików z 16 dodań i 13 usunięć

Wyświetl plik

@ -159,26 +159,29 @@ export abstract class BaseTask<
): this { ): this {
const hooks = hookType === 'before' ? this._preHooks : this._postHooks const hooks = hookType === 'before' ? this._preHooks : this._postHooks
let found = false
if (typeof hookOrName === 'string') { if (typeof hookOrName === 'string') {
const hookObj = hooks.find((h) => h.name === hookOrName) for (const hookObj of hooks) {
if (!hookObj) { if (hookObj.name === hookOrName) {
throw new Error( found = true
`Could not find a ${hookType}-call hook named "${hookOrName}" to change its priority` hookObj.priority = newPriority
) }
}
} else {
for (const hookObj of hooks) {
if (hookObj.hook === hookOrName) {
found = true
hookObj.priority = newPriority
}
}
} }
hookObj.priority = newPriority if (!found) {
} else {
const hookObj = hooks.find((h) => h.hook === hookOrName)
if (!hookObj) {
throw new Error( throw new Error(
`Could not find the provided ${hookType}-call hook to change its priority` `Could not find the provided ${hookType}-call hook to change its priority`
) )
} }
hookObj.priority = newPriority
}
hooks.sort((a, b) => b.priority - a.priority) hooks.sort((a, b) => b.priority - a.priority)
return this return this
} }