1 line
9.3 KiB
JSON
1 line
9.3 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/Аришина)/Desktop/promo/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`.\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}"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,oCAAoC;AACzD,SAASC,UAAU,QAAQ,gBAAgB;AAC3C,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B;AACA;AACA;AACA,eAAe,SAASC,eAAeA,CAAA,EAAG;EACxC,IAAIC,gBAAgB,GAAG,aAAaF,KAAK,CAACG,aAAa,CAAC,IAAI,CAAC;;EAE7D;AACF;AACA;AACA;A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