UNPKG

4.77 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../src/redux/index.ts"],"names":["emitter","readState","state","nodes","nodesByType","Map","forEach","node","type","internal","has","set","get","id","e","multi","dispatch","next","action","Array","isArray","filter","Boolean","map","configureStore","initialState","reducers","thunk","store","saveState","getState","status","componentDataDependencies","components","jobsV2","staticQueryComponents","webpackCompilationHash","pageDataStats","subscribe","lastAction","emit"],"mappings":";;;;;;;AAAA;;AASA;;AACA;;AACA;;AACA;;AAIO,MAAMA,OAAO,GAAG,oBAAhB,C,CAEP;;;;AACO,MAAMC,SAAS,GAAG,MAAmB;AAC1C,MAAI;AACF,UAAMC,KAAK,GAAG,6BAAd;;AACA,QAAIA,KAAK,CAACC,KAAV,EAAiB;AACf;AACAD,MAAAA,KAAK,CAACE,WAAN,GAAoB,IAAIC,GAAJ,EAApB;AACAH,MAAAA,KAAK,CAACC,KAAN,CAAYG,OAAZ,CAAoBC,IAAI,IAAI;AAC1B,cAAM;AAAEC,UAAAA;AAAF,YAAWD,IAAI,CAACE,QAAtB;;AACA,YAAI,CAACP,KAAK,CAACE,WAAN,CAAmBM,GAAnB,CAAuBF,IAAvB,CAAL,EAAmC;AACjCN,UAAAA,KAAK,CAACE,WAAN,CAAmBO,GAAnB,CAAuBH,IAAvB,EAA6B,IAAIH,GAAJ,EAA7B;AACD;;AACDH,QAAAA,KAAK,CAACE,WAAN,CAAmBQ,GAAnB,CAAuBJ,IAAvB,EAA6BG,GAA7B,CAAiCJ,IAAI,CAACM,EAAtC,EAA0CN,IAA1C;AACD,OAND;AAOD,KAZC,CAcF;AACA;AACA;;;AACA,WAAOL,KAAK,CAAE,eAAF,CAAZ;AACA,WAAOA,KAAP;AACD,GAnBD,CAmBE,OAAOY,CAAP,EAAU,CAEX,CAFC,CACA;AAEF;AACA;;;AACA,SAAO,EAAP;AACD,CA1BM;AA4BP;;;;;;;AAGA,MAAMC,KAAiB,GAAG,CAAC;AAAEC,EAAAA;AAAF,CAAD,KAAkBC,IAAI,IAC9CC,MADkD,IAGlDC,KAAK,CAACC,OAAN,CAAcF,MAAd,IAAwBA,MAAM,CAACG,MAAP,CAAcC,OAAd,EAAuBC,GAAvB,CAA2BP,QAA3B,CAAxB,GAA+DC,IAAI,CAACC,MAAD,CAHrE;;AAKO,MAAMM,cAAc,GAAIC,YAAD,IAC5B,wBACE,8CAAqBC,iBAArB,EADF,EAEED,YAFF,EAGE,4BAAgBE,mBAAhB,EAAuBZ,KAAvB,CAHF,CADK;;;AAOA,MAAMa,KAAK,GAAGJ,cAAc,CAACvB,SAAS,EAAV,CAA5B,C,CAEP;;;;AACO,MAAM4B,SAAS,GAAG,MAAY;AACnC,QAAM3B,KAAK,GAAG0B,KAAK,CAACE,QAAN,EAAd;AAEA,SAAO,2BAAa;AAClB3B,IAAAA,KAAK,EAAED,KAAK,CAACC,KADK;AAElB4B,IAAAA,MAAM,EAAE7B,KAAK,CAAC6B,MAFI;AAGlBC,IAAAA,yBAAyB,EAAE9B,KAAK,CAAC8B,yBAHf;AAIlBC,IAAAA,UAAU,EAAE/B,KAAK,CAAC+B,UAJA;AAKlBC,IAAAA,MAAM,EAAEhC,KAAK,CAACgC,MALI;AAMlBC,IAAAA,qBAAqB,EAAEjC,KAAK,CAACiC,qBANX;AAOlBC,IAAAA,sBAAsB,EAAElC,KAAK,CAACkC,sBAPZ;AAQlBC,IAAAA,aAAa,EAAEnC,KAAK,CAACmC;AARH,GAAb,CAAP;AAUD,CAbM;;;AAePT,KAAK,CAACU,SAAN,CAAgB,MAAM;AACpB,QAAMC,UAAU,GAAGX,KAAK,CAACE,QAAN,GAAiBS,UAApC;AACAvC,EAAAA,OAAO,CAACwC,IAAR,CAAaD,UAAU,CAAC/B,IAAxB,EAA8B+B,UAA9B;AACD,CAHD","sourcesContent":["import {\n applyMiddleware,\n combineReducers,\n createStore,\n Store,\n Middleware,\n} from \"redux\"\nimport _ from \"lodash\"\n\nimport mitt from \"mitt\"\nimport thunk from \"redux-thunk\"\nimport reducers from \"./reducers\"\nimport { writeToCache, readFromCache } from \"./persist\"\nimport { IReduxState, ActionsUnion } from \"./types\"\n\n// Create event emitter for actions\nexport const emitter = mitt()\n\n// Read old node data from cache.\nexport const readState = (): IReduxState => {\n try {\n const state = readFromCache() as IReduxState\n if (state.nodes) {\n // re-create nodesByType\n state.nodesByType = new Map()\n state.nodes.forEach(node => {\n const { type } = node.internal\n if (!state.nodesByType!.has(type)) {\n state.nodesByType!.set(type, new Map())\n }\n state.nodesByType!.get(type).set(node.id, node)\n })\n }\n\n // jsonDataPaths was removed in the per-page-manifest\n // changes. Explicitly delete it here to cover case where user\n // runs gatsby the first time after upgrading.\n delete state[`jsonDataPaths`]\n return state\n } catch (e) {\n // ignore errors.\n }\n // BUG: Would this not cause downstream bugs? seems likely. Why wouldn't we just\n // throw and kill the program?\n return {} as IReduxState\n}\n\n/**\n * Redux middleware handling array of actions\n */\nconst multi: Middleware = ({ dispatch }) => next => (\n action: ActionsUnion\n): ActionsUnion | ActionsUnion[] =>\n Array.isArray(action) ? action.filter(Boolean).map(dispatch) : next(action)\n\nexport const configureStore = (initialState: IReduxState): Store<IReduxState> =>\n createStore(\n combineReducers({ ...reducers }),\n initialState,\n applyMiddleware(thunk, multi)\n )\n\nexport const store = configureStore(readState())\n\n// Persist state.\nexport const saveState = (): void => {\n const state = store.getState()\n\n return writeToCache({\n nodes: state.nodes,\n status: state.status,\n componentDataDependencies: state.componentDataDependencies,\n components: state.components,\n jobsV2: state.jobsV2,\n staticQueryComponents: state.staticQueryComponents,\n webpackCompilationHash: state.webpackCompilationHash,\n pageDataStats: state.pageDataStats,\n })\n}\n\nstore.subscribe(() => {\n const lastAction = store.getState().lastAction\n emitter.emit(lastAction.type, lastAction)\n})\n"],"file":"index.js"}
\No newline at end of file