Skip to content

Commit

Permalink
feat(utils): add mergeFunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
wewoor committed Dec 11, 2020
1 parent 30c6f51 commit 4c09efa
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export function cloneInstance<T>(origin: T) {
const prototypes = Object.getPrototypeOf(origin) || {};
Object.keys(prototypes).forEach((prop) => {
if (typeof prototypes[prop] === 'function') {
console.log('bind:', prototypes[prop], origin);
prototypes[prop].bind(origin);
}
});
Expand All @@ -16,6 +15,16 @@ export function cloneInstance<T>(origin: T) {
...prototypes,
};
} catch (e) {
console.error('cloneInstance error:', e);
console.error('Function cloneInstance error:', e);
}
}

/**
* Merge multiple functions to one function
* @param funcs
*/
export function mergeFunctions(...funcs) {
return function (...args) {
funcs.filter((fn) => !!fn).forEach((fn) => fn?.(...args));
};
}

0 comments on commit 4c09efa

Please sign in to comment.