@progress/kendo-angular-schematics
Version:
Kendo UI Schematics for Angular
33 lines (30 loc) • 1.21 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
const createReboundMethod = (target, source, name) => {
const method = source[name];
if (typeof method !== 'function') {
throw new Error(`Attempt to rebind ${name} which isn't a function on the source object`);
}
return (...args) => {
var value = method.apply(source, args);
return value === source ? target : value;
};
};
const createTransform = (transforms) =>
(name) => transforms.reduce(
(name, fn) => name && fn(name),
name
);
const rebindAll = (target, source, ...transforms) => {
const transform = createTransform(transforms);
for (const name of Object.keys(source)) {
const result = transform(name);
if (result) {
target[result] = createReboundMethod(target, source, name);
}
}
return target;
};
exports.rebindAll = rebindAll;