Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.141/page_editor/app/contexts/StoreContext",["module","exports","require","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$react","../components/undo/useUndo"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.StoreAPIContextProvider=StoreAPIContextProvider,t.StoreContextProvider=function StoreContextProvider({children:e,initialState:t,reducer:r}){const[c,a]=function useThunk([e,t]){const r=(0,n.useIsMounted)(),o=(0,u.useRef)(e);o.current=e;const c=(0,u.useRef)((e=>{if(r()){if("function"==typeof e)return e((e=>{r()&&t(e)}),(()=>o.current));t(e)}}));return[e,c.current]}((0,o.default)((0,u.useReducer)(r,t))),i=(0,u.useRef)(c),s=(0,u.useCallback)((()=>i.current),[]);return i.current=c,u.default.createElement(StoreAPIContextProvider,{dispatch:a,getState:s},e)},t.useDispatch=function useDispatch(){return(0,u.useContext)(e)},t.useGetState=function useGetState(){return(0,u.useContext)(c)},t.useSelectorCallback=useSelectorCallback,t.useSelector=useSelector,t.useSelectorRef=function useSelectorRef(e){const t=(0,u.useRef)(null);return useSelector((r=>{t.current=e(r)})),t};var n=r("@liferay/frontend-js-react-web"),u=function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if(Object.prototype.hasOwnProperty.call(e,u)){var o=n?Object.getOwnPropertyDescriptor(e,u):null;o&&(o.get||o.set)?Object.defineProperty(r,u,o):r[u]=e[u]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),o=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(r("../components/undo/useUndo"));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}const e=u.default.createContext((()=>{})),c=u.default.createContext(null),a=u.default.createContext((()=>{})),DEFAULT_COMPARE_EQUAL=(e,t)=>e===t,DEFAULT_DISPATCH=()=>{},DEFAULT_GET_STATE=()=>({});class EventEmitter{constructor(){this._listeners=new Map,this._nextListenerId=0}addListener(e){const t=this._nextListenerId++;return this._listeners.set(t,e),{removeListener:()=>{this._listeners.delete(t)}}}emit(e){for(const t of this._listeners.values())try{t(e)}catch(e){}}}function StoreAPIContextProvider({children:t,dispatch:r=DEFAULT_DISPATCH,getState:n=DEFAULT_GET_STATE}){const[o]=(0,u.useState)((()=>new EventEmitter)),i=n(),s=(0,u.useCallback)((e=>o.addListener(e)),[o]);return(0,u.useEffect)((()=>{o.emit(i)}),[o,i]),u.default.createElement(a.Provider,{value:s},u.default.createElement(e.Provider,{value:r},u.default.createElement(c.Provider,{value:n},t)))}function useSelectorCallback(e,t,r=DEFAULT_COMPARE_EQUAL){const n=(0,u.useContext)(c),o=(0,u.useContext)(a),i=(0,u.useMemo)((()=>e(n())),[]),[s,l]=(0,u.useReducer)(((e,t)=>void 0===t||r(e,t)?e:t),i),d=(0,u.useCallback)(e,t);return(0,u.useEffect)((()=>{l(d(n()));const e=o((e=>{l(d(e))}));return()=>{e.removeListener()}}),[n,d,o]),s}function useSelector(e,t=DEFAULT_COMPARE_EQUAL){return useSelectorCallback(e,[],t)}}}));
//# sourceMappingURL=StoreContext.js.map