Skip to content

Commit 4c09efa

Browse files
committed
feat(utils): add mergeFunctions
1 parent 30c6f51 commit 4c09efa

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/common/utils.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export function cloneInstance<T>(origin: T) {
77
const prototypes = Object.getPrototypeOf(origin) || {};
88
Object.keys(prototypes).forEach((prop) => {
99
if (typeof prototypes[prop] === 'function') {
10-
console.log('bind:', prototypes[prop], origin);
1110
prototypes[prop].bind(origin);
1211
}
1312
});
@@ -16,6 +15,16 @@ export function cloneInstance<T>(origin: T) {
1615
...prototypes,
1716
};
1817
} catch (e) {
19-
console.error('cloneInstance error:', e);
18+
console.error('Function cloneInstance error:', e);
2019
}
2120
}
21+
22+
/**
23+
* Merge multiple functions to one function
24+
* @param funcs
25+
*/
26+
export function mergeFunctions(...funcs) {
27+
return function (...args) {
28+
funcs.filter((fn) => !!fn).forEach((fn) => fn?.(...args));
29+
};
30+
}

0 commit comments

Comments
 (0)