Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.132/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){var n;window;{Object.defineProperty(t,"__esModule",{value:!0}),t.StoreAPIContextProvider=a,t.StoreContextProvider=function({children:e,initialState:t,reducer:r}){const[n,c]=function([e,t]){const r=(0,u.useIsMounted)(),n=(0,o.useRef)(e);n.current=e;const s=(0,o.useRef)((e=>{if(r()){if("function"==typeof e)return e((e=>{r()&&t(e)}),(()=>n.current));t(e)}}));return[e,s.current]}((0,s.default)((0,o.useReducer)(r,t))),i=(0,o.useRef)(n),f=(0,o.useCallback)((()=>i.current),[]);return i.current=n,o.default.createElement(a,{dispatch:c,getState:f},e)},t.useDispatch=function(){return(0,o.useContext)(e)},t.useGetState=function(){return(0,o.useContext)(l)},t.useSelectorCallback=i,t.useSelector=f,t.useSelectorRef=function(e){const t=(0,o.useRef)(null);return f((r=>{t.current=e(r)})),t};var u=r("@liferay/frontend-js-react-web"),o=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=c();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")),s=(n=r("../components/undo/useUndo"))&&n.__esModule?n:{default:n};function c(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return c=function(){return e},e}const e=o.default.createContext((()=>{})),l=o.default.createContext(null),d=o.default.createContext((()=>{})),p=(e,t)=>e===t,v=()=>{},y=()=>({});class b{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 a({children:t,dispatch:r=v,getState:n=y}){const[u]=(0,o.useState)((()=>new b)),s=n(),c=(0,o.useCallback)((e=>u.addListener(e)),[u]);return(0,o.useEffect)((()=>{u.emit(s)}),[u,s]),o.default.createElement(d.Provider,{value:c},o.default.createElement(e.Provider,{value:r},o.default.createElement(l.Provider,{value:n},t)))}function i(e,t,r=p){const n=(0,o.useContext)(l),u=(0,o.useContext)(d),s=(0,o.useMemo)((()=>e(n())),[]),[c,a]=(0,o.useReducer)(((e,t)=>void 0===t||r(e,t)?e:t),s),i=(0,o.useCallback)(e,t);return(0,o.useEffect)((()=>{a(i(n()));const e=u((e=>{a(i(e))}));return()=>{e.removeListener()}}),[n,i,u]),c}function f(e,t=p){return i(e,[],t)}}}));
//# sourceMappingURL=StoreContext.js.map