Skip to content

Commit

Permalink
refactor: one-time cleanups use for instead of foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
twnlink committed Aug 20, 2024
1 parent 3c2b5fc commit a929b5e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spitroast",
"version": "2.0.1",
"version": "2.0.2",
"description": "A simple JavaScript function patcher.",
"main": "dist/cjs.js",
"module": "dist/esm/index.js",
Expand Down
6 changes: 3 additions & 3 deletions src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ export default function (
// This calls the original function
(...args: unknown[]) =>
isConstruct
? Reflect.construct(patch.o, args, ctxt)
: patch.o.apply(ctxt, args)
? Reflect.construct(origFunc, args, ctxt)
: origFunc.apply(ctxt, args)
)(...funcArgs);

// After patches
for (const hook of patch.a.values())
workingRetVal = hook.call(ctxt, funcArgs, workingRetVal) ?? workingRetVal;

// Cleanups (one-times)
patch.c.forEach((c) => c());
for (const cleanup of patch.c) cleanup()
patch.c = [];

return workingRetVal;
Expand Down

0 comments on commit a929b5e

Please sign in to comment.