Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.169/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)(),u=(0,o.useRef)(e);u.current=e;const c=(0,o.useRef)((e=>{if(r()){if("function"==typeof e)return e((e=>{r()&&t(e)}),(()=>u.current));t(e)}}));return[e,c.current]}((0,u.default)((0,o.useReducer)(r,t))),i=(0,o.useRef)(c),s=(0,o.useCallback)((()=>i.current),[]);return i.current=c,o.default.createElement(StoreAPIContextProvider,{dispatch:a,getState:s},e)},t.useDispatch=function useDispatch(){return(0,o.useContext)(e)},t.useGetState=function useGetState(){return(0,o.useContext)(c)},t.useSelectorCallback=useSelectorCallback,t.useSelector=useSelector,t.useSelectorRef=function useSelectorRef(e){const t=(0,o.useRef)(null);return useSelector((r=>{t.current=e(r)})),t};var n=r("@liferay/frontend-js-react-web"),o=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 o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var u=n?Object.getOwnPropertyDescriptor(e,o):null;u&&(u.get||u.set)?Object.defineProperty(r,o,u):r[o]=e[o]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),u=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 DEFAULT_COMPARE_EQUAL=(e,t)=>e===t,DEFAULT_DISPATCH=()=>{},DEFAULT_GET_STATE=()=>({}),e=o.default.createContext(DEFAULT_DISPATCH),c=o.default.createContext(DEFAULT_GET_STATE),a=o.default.createContext((()=>{}));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[u]=(0,o.useState)((()=>new EventEmitter)),i=n(),s=(0,o.useCallback)((e=>u.addListener(e)),[u]);return(0,o.useEffect)((()=>{u.emit(i)}),[u,i]),o.default.createElement(a.Provider,{value:s},o.default.createElement(e.Provider,{value:r},o.default.createElement(c.Provider,{value:n},t)))}function useSelectorCallback(e,t,r=DEFAULT_COMPARE_EQUAL){const n=(0,o.useContext)(c),u=(0,o.useContext)(a),i=(0,o.useMemo)((()=>e(n())),[]),[s,l]=(0,o.useReducer)(((e,t)=>void 0===t||r(e,t)?e:t),i),d=(0,o.useCallback)(e,t);return(0,o.useEffect)((()=>{l(d(n()));const e=u((e=>{l(d(e))}));return()=>{e&&e.removeListener()}}),[n,d,u]),s}function useSelector(e,t=DEFAULT_COMPARE_EQUAL){return useSelectorCallback(e,[],t)}}}));
//# sourceMappingURL=StoreContext.js.map