1 line
9.4 KiB
JSON
1 line
9.4 KiB
JSON
|
{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport { supportRef } from \"rc-util/es/ref\";\nimport * as React from 'react';\n/**\n * Create Immutable pair for `makeImmutable` and `responseImmutable`.\n */\nexport default function createImmutable() {\n var ImmutableContext = /*#__PURE__*/React.createContext(null);\n\n /**\n * Get render update mark by `makeImmutable` root.\n * Do not deps on the return value as render times\n * but only use for `useMemo` or `useCallback` deps.\n */\n function useImmutableMark() {\n return React.useContext(ImmutableContext);\n }\n\n /**\n * Wrapped Component will be marked as Immutable.\n * When Component parent trigger render,\n * it will notice children component (use with `responseImmutable`) node that parent has updated.\n * @param Component Passed Component\n * @param triggerRender Customize trigger `responseImmutable` children re-render logic. Default will always trigger re-render when this component re-render.\n */\n function makeImmutable(Component, shouldTriggerRender) {\n var refAble = supportRef(Component);\n var ImmutableComponent = function ImmutableComponent(props, ref) {\n var refProps = refAble ? {\n ref: ref\n } : {};\n var renderTimesRef = React.useRef(0);\n var prevProps = React.useRef(props);\n\n // If parent has the context, we do not wrap it\n var mark = useImmutableMark();\n if (mark !== null) {\n return /*#__PURE__*/React.createElement(Component, _extends({}, props, refProps));\n }\n if (\n // Always trigger re-render if not provide `notTriggerRender`\n !shouldTriggerRender || shouldTriggerRender(prevProps.current, props)) {\n renderTimesRef.current += 1;\n }\n prevProps.current = props;\n return /*#__PURE__*/React.createElement(ImmutableContext.Provider, {\n value: renderTimesRef.current\n }, /*#__PURE__*/React.createElement(Component, _extends({}, props, refProps)));\n };\n if (process.env.NODE_ENV !== 'production') {\n ImmutableComponent.displayName = \"ImmutableRoot(\".concat(Component.displayName || Component.name, \")\");\n }\n return refAble ? /*#__PURE__*/React.forwardRef(ImmutableComponent) : ImmutableComponent;\n }\n\n /**\n * Wrapped Component with `React.memo`.\n * But will rerender when parent with `makeImmutable` rerender.\n */\n function responseImmutable(Component, propsAreEqual) {\n var refAble = supportRef(Component);\n var ImmutableComponent = function ImmutableComponent(props, ref) {\n var refProps = refAble ? {\n ref: ref\n } : {};\n useImmutableMark();\n return /*#__PURE__*/React.createElement(Component, _extends({}, props, refProps));\n };\n if (process.env.NODE_ENV !== 'production') {\n ImmutableComponent.displayName = \"ImmutableResponse(\".concat(Component.displayName || Component.name, \")\");\n }\n return refAble ? /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(ImmutableComponent), propsAreEqual) : /*#__PURE__*/React.memo(ImmutableComponent, propsAreEqual);\n }\n return {\n makeImmutable: makeImmutable,\n responseImmutable: responseImmutable,\n useImmutableMark: useImmutableMark\n };\n}","map":{"version":3,"names":["_extends","supportRef","React","createImmutable","ImmutableContext","createContext","useImmutableMark","useContext","makeImmutable","Component","shouldTriggerRender","refAble","ImmutableComponent","props","ref","refProps","renderTimesRef","useRef","prevProps","mark","createElement","current","Provider","value","process","env","NODE_ENV","displayName","concat","name","forwardRef","responseImmutable","propsAreEqual","memo"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/@rc-component/context/es/Immutable.js"],"sourcesContent":["import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport { supportRef } from \"rc-util/es/ref\";\nimport * as React from 'react';\n/**\n * Create Immutable pair for `makeImmutable` and `responseImmutable
|