mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-01 22:10:27 +00:00
26 lines
492 B
TypeScript
26 lines
492 B
TypeScript
export function bindRuntimeContext<T, U>(x: T, ctx: U): T {
|
|
if (typeof x === 'function') {
|
|
return x.bind(ctx);
|
|
}
|
|
|
|
if (typeof x !== 'object') {
|
|
return x;
|
|
}
|
|
|
|
if (x === null) {
|
|
return null;
|
|
}
|
|
|
|
if (Array.isArray(x)) {
|
|
return (x.map((item) => bindRuntimeContext(item, ctx)) as unknown) as T;
|
|
}
|
|
|
|
const res = {} as Record<string, unknown>;
|
|
|
|
Object.entries(x).forEach(([k, v]) => {
|
|
res[k] = bindRuntimeContext(v, ctx);
|
|
});
|
|
|
|
return (res as unknown) as T;
|
|
}
|