"use strict";Liferay.Loader.define("portal-workflow-kaleo-designer-web$react-redux@7.2.8/lib/components/connectAdvanced",["module","exports","require","@portal-workflow-kaleo-designer-web$babel/runtime/helpers/interopRequireDefault","@portal-workflow-kaleo-designer-web$babel/runtime/helpers/interopRequireWildcard","@portal-workflow-kaleo-designer-web$babel/runtime/helpers/extends","@portal-workflow-kaleo-designer-web$babel/runtime/helpers/objectWithoutPropertiesLoose","portal-workflow-kaleo-designer-web$hoist-non-react-statics","liferay!frontend-js-react-web$react","portal-workflow-kaleo-designer-web$react-is","../utils/Subscription","../utils/useIsomorphicLayoutEffect","./Context"],(function(e,r,t){window;{var o=t("@portal-workflow-kaleo-designer-web$babel/runtime/helpers/interopRequireDefault").default,n=t("@portal-workflow-kaleo-designer-web$babel/runtime/helpers/interopRequireWildcard").default;r.__esModule=!0,r.default=function connectAdvanced(e,r){void 0===r&&(r={});var t=r,o=t.getDisplayName,n=void 0===o?function(e){return"ConnectAdvanced("+e+")"}:o,d=t.methodName,v=void 0===d?"connectAdvanced":d,C=t.renderCountProp,y=void 0===C?void 0:C,g=t.shouldHandleStateChanges,k=void 0===g||g,R=t.storeKey,S=void 0===R?"store":R,x=(t.withRef,t.forwardRef),$=void 0!==x&&x,W=t.context,N=void 0===W?f.ReactReduxContext:W,E=(0,u.default)(t,p),L=N;return function wrapWithConnect(r){var t=r.displayName||r.name||"Component",o=n(t),d=(0,a.default)({},E,{getDisplayName:n,methodName:v,renderCountProp:y,shouldHandleStateChanges:k,storeKey:S,displayName:o,wrappedComponentName:t,WrappedComponent:r}),f=E.pure,p=f?s.useMemo:function(e){return e()};function ConnectFunction(t){var o=(0,s.useMemo)((function(){var e=t.reactReduxForwardedRef,r=(0,u.default)(t,w);return[t.context,e,r]}),[t]),n=o[0],i=o[1],f=o[2],v=(0,s.useMemo)((function(){return n&&n.Consumer&&(0,l.isContextConsumer)(s.default.createElement(n.Consumer,null))?n:L}),[n,L]),C=(0,s.useContext)(v),y=Boolean(t.store)&&Boolean(t.store.getState)&&Boolean(t.store.dispatch);Boolean(C)&&Boolean(C.store);var g=y?t.store:C.store,R=(0,s.useMemo)((function(){return function createChildSelector(r){return e(r.dispatch,d)}(g)}),[g]),S=(0,s.useMemo)((function(){if(!k)return b;var e=(0,c.createSubscription)(g,y?null:C.subscription),r=e.notifyNestedSubs.bind(e);return[e,r]}),[g,y,C]),x=S[0],$=S[1],W=(0,s.useMemo)((function(){return y?C:(0,a.default)({},C,{subscription:x})}),[y,C,x]),N=(0,s.useReducer)(storeStateUpdatesReducer,m,h),E=N[0][0],M=N[1];if(E&&E.error)throw E.error;var P=(0,s.useRef)(),A=(0,s.useRef)(f),F=(0,s.useRef)(),U=(0,s.useRef)(!1),D=p((function(){return F.current&&f===A.current?F.current:R(g.getState(),f)}),[g,E,f]);useIsomorphicLayoutEffectWithArgs(captureWrapperProps,[A,P,U,f,D,F,$]),useIsomorphicLayoutEffectWithArgs(subscribeUpdates,[k,g,x,R,A,P,U,F,$,M],[g,x,R]);var I=(0,s.useMemo)((function(){return s.default.createElement(r,(0,a.default)({},D,{ref:i}))}),[i,r,D]);return(0,s.useMemo)((function(){return k?s.default.createElement(v.Provider,{value:W},I):I}),[v,I,W])}var C=f?s.default.memo(ConnectFunction):ConnectFunction;if(C.WrappedComponent=r,C.displayName=ConnectFunction.displayName=o,$){var g=s.default.forwardRef((function forwardConnectRef(e,r){return s.default.createElement(C,(0,a.default)({},e,{reactReduxForwardedRef:r}))}));return g.displayName=o,g.WrappedComponent=r,(0,i.default)(g,r)}return(0,i.default)(C,r)}};var a=o(t("@portal-workflow-kaleo-designer-web$babel/runtime/helpers/extends")),u=o(t("@portal-workflow-kaleo-designer-web$babel/runtime/helpers/objectWithoutPropertiesLoose")),i=o(t("portal-workflow-kaleo-designer-web$hoist-non-react-statics")),s=n(t("liferay!frontend-js-react-web$react")),l=t("portal-workflow-kaleo-designer-web$react-is"),c=t("../utils/Subscription"),d=t("../utils/useIsomorphicLayoutEffect"),f=t("./Context"),p=["getDisplayName","methodName","renderCountProp","shouldHandleStateChanges","storeKey","withRef","forwardRef","context"],w=["reactReduxForwardedRef"],m=[],b=[null,null];function storeStateUpdatesReducer(e,r){var t=e[1];return[r.payload,t+1]}function useIsomorphicLayoutEffectWithArgs(e,r,t){(0,d.useIsomorphicLayoutEffect)((function(){return e.apply(void 0,r)}),t)}function captureWrapperProps(e,r,t,o,n,a,u){e.current=o,r.current=n,t.current=!1,a.current&&(a.current=null,u())}function subscribeUpdates(e,r,t,o,n,a,u,i,s,l){if(e){var c=!1,d=null,f=function checkForUpdates(){if(!c){var e,t,f=r.getState();try{e=o(f,n.current)}catch(e){t=e,d=e}t||(d=null),e===a.current?u.current||s():(a.current=e,i.current=e,u.current=!0,l({type:"STORE_UPDATED",payload:{error:t}}))}};return t.onStateChange=f,t.trySubscribe(),f(),function unsubscribeWrapper(){if(c=!0,t.tryUnsubscribe(),t.onStateChange=null,d)throw d}}}var h=function initStateUpdates(){return[null,0]}}}));
//# sourceMappingURL=connectAdvanced.js.map