UNPKG

@sassoftware/vi-api

Version:
32 lines (31 loc) 1.29 kB
/* eslint-enable @typescript-eslint/no-deprecated */ export var PageViewerBindingsType; (function (PageViewerBindingsType) { PageViewerBindingsType["CreateObject"] = "CREATE"; PageViewerBindingsType["EditObject"] = "EDIT"; PageViewerBindingsType["ViewObject"] = "VIEW"; PageViewerBindingsType["StaticData"] = "STATIC"; })(PageViewerBindingsType || (PageViewerBindingsType = {})); /** * Merges provided bindings with default bindings. If both are functions, wraps them so both are called. * @param provided The provided bindings. * @param defaults The default bindings. * @returns The merged bindings object. */ export function mergeBindings(provided = {}, defaults = {}) { const merged = { ...provided }; Object.entries(defaults || {}).forEach(([name, defaultBinding]) => { // Use index signature to avoid 'any' and 'Function' types const providedValue = merged[name]; if (typeof defaultBinding === "function" && typeof providedValue === "function") { merged[name] = (...args) => { defaultBinding(...args); return providedValue(...args); }; } else if (providedValue === undefined) { merged[name] = defaultBinding; } }); return merged; }