Skip to content

Commit b2b90f2

Browse files
committed
Use mimic-fn
1 parent 8f35f98 commit b2b90f2

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"json-schema-faker": "0.5.0-rc15",
4848
"lodash": "^4.17.10",
4949
"methods": "^1.1.2",
50+
"mimic-fn": "^1.2.0",
5051
"moize": "^5.4.2",
5152
"node-notifier": "^5.4.0",
5253
"openapi-schema-to-json-schema": "^2.2.0",

src/utils/keep_props.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
'use strict'
22

3+
const mimicFn = require('mimic-fn')
4+
35
// Wraps a functor so it does not modify a function `name`, `length`, etc.
46
const keepProps = function(functor) {
57
return (originalFunc, ...args) => {
68
const wrappedFunc = functor(originalFunc, ...args)
7-
8-
copyProperties({ originalFunc, wrappedFunc })
9-
9+
mimicFn(wrappedFunc, originalFunc)
1010
return wrappedFunc
1111
}
1212
}
1313

14-
const copyProperties = function({ originalFunc, wrappedFunc }) {
15-
Reflect.ownKeys(originalFunc).forEach(propName =>
16-
copyProperty({ originalFunc, wrappedFunc, propName }),
17-
)
18-
}
19-
20-
const copyProperty = function({ originalFunc, wrappedFunc, propName }) {
21-
const prop = Object.getOwnPropertyDescriptor(originalFunc, propName)
22-
// eslint-disable-next-line fp/no-mutating-methods
23-
Object.defineProperty(wrappedFunc, propName, prop)
24-
}
25-
2614
module.exports = {
2715
keepProps,
2816
}

0 commit comments

Comments
 (0)