UNPKG

3.33 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../src/reducers/viewed-resources.js"],"names":["viewedResources","config","currentViewedResources","action","type","resourceViewAction","contentRef","payload","content","ref","contentType","resourceRef","resource","contentIndex","resources","contentResources","resourceAlreadyViewed","newViewedResources"],"mappings":";;;;;;;AAMA,eAAe,SAASA,eAAT,CACbC,MADa,EAE6C;AAC1D,SAAO,CACLC,sBAA6C,GAAG,EAD3C,EAELC,MAFK,KAGqB;AAC1B,YAAQA,MAAM,CAACC,IAAf;AACE,WAAK,UAAL;AAAiB;AACf,gBAAMC,kBAAkB,GAAIF,MAA5B;AACA,gBAAMG,UAAU,GAAGD,kBAAkB,CAACE,OAAnB,CAA2BC,OAA3B,CAAmCC,GAAtD;AACA,gBAAMC,WAAW,GAAGL,kBAAkB,CAACE,OAAnB,CAA2BC,OAA3B,CAAmCJ,IAAvD;AACA,gBAAMO,WAAW,GAAGN,kBAAkB,CAACE,OAAnB,CAA2BK,QAA3B,CAAoCH,GAAxD;;AACA,gBAAMI,YAAY,GAAG,WAAU;AAACJ,YAAAA,GAAG,EAAEH;AAAN,WAAV,EAA6BJ,sBAA7B,CAArB;;AAEA,cAAIW,YAAY,KAAK,CAAC,CAAtB,EAAyB;AACvB,mBAAO,QAAOX,sBAAP,EAA+B,CACpC;AACEO,cAAAA,GAAG,EAAEH,UADP;AAEEF,cAAAA,IAAI,EAAEM,WAFR;AAIEI,cAAAA,SAAS,EAAE,CAACH,WAAD;AAJb,aADoC,CAA/B,CAAP;AAQD;;AAED,gBAAMI,gBAA+B,GAAG,KACtC,WADsC,EAEtCb,sBAAsB,CAACW,YAAD,CAFgB,CAAxC;;AAIA,gBAAMG,qBAAqB,GAAG,UAASL,WAAT,EAAsBI,gBAAtB,CAA9B;;AAEA,cAAIC,qBAAJ,EAA2B,OAAOd,sBAAP,CAxBZ,CAyBf;;AACA,gBAAMe,kBAAkB,GAAG,CAAC,GAAGf,sBAAJ,CAA3B;AACAe,UAAAA,kBAAkB,CAACJ,YAAD,CAAlB,yBACKI,kBAAkB,CAACJ,YAAD,CADvB;AAEEC,YAAAA,SAAS,EAAE,QAAOG,kBAAkB,CAACJ,YAAD,CAAlB,CAAiCC,SAAxC,EAAmD,CAACH,WAAD,CAAnD;AAFb;AAIA,iBAAOM,kBAAP;AACD;;AACD;AACE,eAAOf,sBAAP;AAnCJ;AAqCD,GAzCD;AA0CD","sourcesContent":["// @flow\n\nimport {concat, findIndex, get, includes} from 'lodash/fp';\n\nimport type {Action, Config, ContentResourceViewedAction, ViewedResource} from '../types';\n\nexport default function viewedResources(\n config: Config\n): (Array<ViewedResource>, Action) => Array<ViewedResource> {\n return (\n currentViewedResources: Array<ViewedResource> = [],\n action: Action\n ): Array<ViewedResource> => {\n switch (action.type) {\n case 'resource': {\n const resourceViewAction = (action: ContentResourceViewedAction);\n const contentRef = resourceViewAction.payload.content.ref;\n const contentType = resourceViewAction.payload.content.type;\n const resourceRef = resourceViewAction.payload.resource.ref;\n const contentIndex = findIndex({ref: contentRef}, currentViewedResources);\n\n if (contentIndex === -1) {\n return concat(currentViewedResources)([\n {\n ref: contentRef,\n type: contentType,\n\n resources: [resourceRef]\n }\n ]);\n }\n\n const contentResources: Array<string> = get(\n 'resources',\n currentViewedResources[contentIndex]\n );\n const resourceAlreadyViewed = includes(resourceRef, contentResources);\n\n if (resourceAlreadyViewed) return currentViewedResources;\n // return currentViewedResources, contentIndex, resourceRef;\n const newViewedResources = [...currentViewedResources];\n newViewedResources[contentIndex] = {\n ...newViewedResources[contentIndex],\n resources: concat(newViewedResources[contentIndex].resources, [resourceRef])\n };\n return newViewedResources;\n }\n default:\n return currentViewedResources;\n }\n };\n}\n"],"file":"viewed-resources.js"}
\No newline at end of file