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zE,CAAC;IAFD,wCAEC","sourcesContent":["const REACT_LIFECYCLE_EXCLUSIONS = [\n 'setState',\n 'render',\n 'componentWillMount',\n 'UNSAFE_componentWillMount',\n 'componentDidMount',\n 'componentWillReceiveProps',\n 'UNSAFE_componentWillReceiveProps',\n 'shouldComponentUpdate',\n 'componentWillUpdate',\n 'getSnapshotBeforeUpdate',\n 'UNSAFE_componentWillUpdate',\n 'componentDidUpdate',\n 'componentWillUnmount',\n];\n\n/**\n * Allows you to hoist methods, except those in an exclusion set from a source object into a destination object.\n *\n * @public\n * @param destination - The instance of the object to hoist the methods onto.\n * @param source - The instance of the object where the methods are hoisted from.\n * @param exclusions - (Optional) What methods to exclude from being hoisted.\n * @returns An array of names of methods that were hoisted.\n */\nexport function hoistMethods(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n destination: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n source: any,\n exclusions: string[] = REACT_LIFECYCLE_EXCLUSIONS,\n): string[] {\n let hoisted: string[] = [];\n for (let methodName in source) {\n if (\n typeof source[methodName] === 'function' &&\n destination[methodName] === undefined &&\n (!exclusions || exclusions.indexOf(methodName) === -1)\n ) {\n hoisted.push(methodName);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n destination[methodName] = function(...args: any[]): void {\n source[methodName](...args);\n };\n }\n }\n\n return hoisted;\n}\n\n/**\n * Provides a method for convenience to unhoist hoisted methods.\n *\n * @public\n * @param source - The source object upon which methods were hoisted.\n * @param methodNames - An array of method names to unhoist.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function unhoistMethods(source: any, methodNames: string[]): void {\n methodNames.forEach((methodName: string) => delete source[methodName]);\n}\n"]} |