-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix applyAspect correctly being apply to whole class methods inc…
…luding constructor
- Loading branch information
Showing
3 changed files
with
9 additions
and
11 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,14 +1,12 @@ | ||
export function applyAspect (advicePool: any) { | ||
export function applyAspect ({ constructor = [], ...methodAdvices }: any) { | ||
return function (target) { | ||
for (let key in advicePool) { | ||
if (key === "constructor") { | ||
advicePool[key].forEach(advice => target = advice(target)) | ||
} else { | ||
advicePool[key].forEach(advice => { | ||
Object.defineProperty(target.prototype, key, advice(target, key, Object.getOwnPropertyDescriptor(target.prototype, key))) | ||
}) | ||
} | ||
for (let key in methodAdvices) { | ||
methodAdvices[key].forEach(advice => | ||
Object.defineProperty(target.prototype, key, | ||
advice(target, key, Object.getOwnPropertyDescriptor(target.prototype, key)))) | ||
} | ||
|
||
constructor.forEach(advice => target = advice(target)) | ||
return target | ||
} | ||
} |
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