UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

33 lines (32 loc) 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getObjectProxy = void 0; /** * The functions gets a new object proxy. This is used for theme to ensure regardless of a partial theme object * there will be a fallback theme object so that properties aren't undefined regardless of the `target` object. * This function will also handle nested properties. * @param target A partial object with up to the same shape as the `fallback` object * @param fallback A fallback object. If a property to be accessed from the proxy is not available on the target object, the fallback object will be used */ function getObjectProxy(target, fallback) { if (target) { return new Proxy(target, { get(target, prop, receiver) { if (typeof fallback[prop] === 'object') { // @ts-ignore return getObjectProxy(target[prop], fallback[prop]); } const targetProp = target[prop]; if (targetProp !== undefined) { return targetProp; } return Reflect.get(fallback, prop, receiver); }, ownKeys() { return Reflect.ownKeys(fallback); }, }); } return fallback; } exports.getObjectProxy = getObjectProxy;