-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hooks): fix some errors for feathers integration (#67)
- Loading branch information
1 parent
73598a4
commit fcfc0ca
Showing
4 changed files
with
45 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Middleware } from './compose'; | ||
import { copyToSelf } from './utils'; | ||
import { copyToSelf, copyProperties } from './utils'; | ||
|
||
export const HOOKS: string = Symbol('@feathersjs/hooks') as any; | ||
|
||
|
@@ -46,50 +46,42 @@ export class HookManager { | |
getMiddleware (): Middleware[]|null { | ||
const previous = this._parent?.getMiddleware(); | ||
|
||
if (previous) { | ||
if (this._middleware) { | ||
return previous.concat(this._middleware); | ||
} | ||
|
||
return previous; | ||
if (previous && this._middleware) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bertho-zero
Author
Collaborator
|
||
return previous.concat(this._middleware); | ||
} | ||
|
||
return this._middleware; | ||
return previous || this._middleware; | ||
} | ||
|
||
collectMiddleware (self: any, _args: any[]): Middleware[] { | ||
const otherMiddleware = getMiddleware(self); | ||
const middleware = this.getMiddleware(); | ||
|
||
if (otherMiddleware) { | ||
if (middleware) { | ||
return otherMiddleware.concat(middleware); | ||
} | ||
|
||
return otherMiddleware; | ||
if (otherMiddleware && middleware) { | ||
return otherMiddleware.concat(middleware); | ||
} | ||
|
||
return middleware; | ||
return otherMiddleware || middleware; | ||
} | ||
|
||
props (props: HookContextData) { | ||
if (!this._props) { | ||
this._props = {}; | ||
} | ||
|
||
Object.assign(this._props, props); | ||
copyProperties(this._props, props); | ||
|
||
return this; | ||
} | ||
|
||
getProps (): HookContextData { | ||
const previous = this._parent?.getProps(); | ||
|
||
if (previous) { | ||
return Object.assign({}, previous, this._props); | ||
if (previous && this._props) { | ||
return copyProperties({}, previous, this._props); | ||
} | ||
|
||
return this._props; | ||
return previous || this._props; | ||
} | ||
|
||
params (...params: string[]) { | ||
|
@@ -101,6 +93,10 @@ export class HookManager { | |
getParams (): string[] { | ||
const previous = this._parent?.getParams(); | ||
|
||
if (previous && this._params) { | ||
return previous.concat(this._params); | ||
} | ||
|
||
return previous || this._params; | ||
} | ||
|
||
|
@@ -114,11 +110,11 @@ export class HookManager { | |
const defaults = typeof this._defaults === 'function' ? this._defaults(self, args, context) : null; | ||
const previous = this._parent?.getDefaults(self, args, context); | ||
|
||
if (previous) { | ||
return Object.assign({}, previous, this._props); | ||
if (previous && defaults) { | ||
return Object.assign({}, previous, defaults); | ||
} | ||
|
||
return defaults; | ||
return previous || defaults; | ||
} | ||
|
||
getContextClass (Base: HookContextConstructor = HookContext): HookContextConstructor { | ||
|
@@ -151,7 +147,7 @@ export class HookManager { | |
} | ||
|
||
if (props) { | ||
Object.assign(ContextClass.prototype, props); | ||
copyProperties(ContextClass.prototype, props); | ||
} | ||
|
||
return ContextClass; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Suggestion: This type of condition can be simplified with an "early return" or "fail fast" logic.
This can be applied at line 60, 80 and 96 too.