UNPKG

@coorpacademy/progression-engine

Version:

35 lines (33 loc) 1.32 kB
import find from 'lodash/fp/find'; import includes from 'lodash/fp/includes'; export default function stars(config) { return (currentStars = 0, action, state) => { switch (action.type) { case 'answer': { const answerAction = action; return !answerAction.payload.instructions && answerAction.payload.isCorrect ? currentStars + config.starsPerCorrectAnswer : currentStars; } case 'clue': { const requestedClueAction = action; const slideRef = requestedClueAction.payload.content.ref; return includes(slideRef, state.requestedClues) ? currentStars : currentStars + config.starsPerAskingClue; } case 'resource': { const contentResourceViewedAction = action; const contentRef = contentResourceViewedAction.payload.content.ref; const contentType = contentResourceViewedAction.payload.content.type; const contentResourceAlreadyViewed = Boolean(find({ type: contentType, ref: contentRef }, state.viewedResources)); if (contentResourceAlreadyViewed) { return currentStars; } return currentStars + config.starsPerResourceViewed; } default: return currentStars; } }; } //# sourceMappingURL=stars.js.map