UNPKG

2.36 kBSource Map (JSON)View Raw
1{"version":3,"file":"redirects.js","names":["redirects","Map","exists","newRedirect","fromPathRedirects","get","fromPath","some","redirect","add","samePathRedirects","set","push","redirectsReducer","state","action","type","payload"],"sources":["../../../src/redux/reducers/redirects.ts"],"sourcesContent":["import _ from \"lodash\"\nimport { IGatsbyState, IRedirect, ICreateRedirectAction } from \"../types\"\n\nconst redirects = new Map<string, Array<IRedirect>>()\n\nfunction exists(newRedirect: IRedirect): boolean {\n const fromPathRedirects = redirects.get(newRedirect.fromPath)\n\n if (!fromPathRedirects) return false\n\n return fromPathRedirects.some(redirect => _.isEqual(redirect, newRedirect))\n}\n\nfunction add(redirect: IRedirect): void {\n let samePathRedirects = redirects.get(redirect.fromPath)\n\n if (!samePathRedirects) {\n samePathRedirects = []\n redirects.set(redirect.fromPath, samePathRedirects)\n }\n\n samePathRedirects.push(redirect)\n}\n\nexport const redirectsReducer = (\n state: IGatsbyState[\"redirects\"] = [],\n action: ICreateRedirectAction\n): IGatsbyState[\"redirects\"] => {\n switch (action.type) {\n case `CREATE_REDIRECT`: {\n const redirect = action.payload\n\n // Add redirect only if it wasn't yet added to prevent duplicates\n if (!exists(redirect)) {\n add(redirect)\n\n state.push(redirect)\n }\n\n return state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;AAGA,MAAMA,SAAS,GAAG,IAAIC,GAAG,EAA4B;AAErD,SAASC,MAAM,CAACC,WAAsB,EAAW;EAC/C,MAAMC,iBAAiB,GAAGJ,SAAS,CAACK,GAAG,CAACF,WAAW,CAACG,QAAQ,CAAC;EAE7D,IAAI,CAACF,iBAAiB,EAAE,OAAO,KAAK;EAEpC,OAAOA,iBAAiB,CAACG,IAAI,CAACC,QAAQ,IAAI,uBAAUA,QAAQ,EAAEL,WAAW,CAAC,CAAC;AAC7E;AAEA,SAASM,GAAG,CAACD,QAAmB,EAAQ;EACtC,IAAIE,iBAAiB,GAAGV,SAAS,CAACK,GAAG,CAACG,QAAQ,CAACF,QAAQ,CAAC;EAExD,IAAI,CAACI,iBAAiB,EAAE;IACtBA,iBAAiB,GAAG,EAAE;IACtBV,SAAS,CAACW,GAAG,CAACH,QAAQ,CAACF,QAAQ,EAAEI,iBAAiB,CAAC;EACrD;EAEAA,iBAAiB,CAACE,IAAI,CAACJ,QAAQ,CAAC;AAClC;AAEO,MAAMK,gBAAgB,GAAG,CAC9BC,KAAgC,GAAG,EAAE,EACrCC,MAA6B,KACC;EAC9B,QAAQA,MAAM,CAACC,IAAI;IACjB,KAAM,iBAAgB;MAAE;QACtB,MAAMR,QAAQ,GAAGO,MAAM,CAACE,OAAO;;QAE/B;QACA,IAAI,CAACf,MAAM,CAACM,QAAQ,CAAC,EAAE;UACrBC,GAAG,CAACD,QAAQ,CAAC;UAEbM,KAAK,CAACF,IAAI,CAACJ,QAAQ,CAAC;QACtB;QAEA,OAAOM,KAAK;MACd;IAEA;MACE,OAAOA,KAAK;EAAA;AAElB,CAAC;AAAA"}
\No newline at end of file