UNPKG

@coorpacademy/progression-engine

Version:

36 lines 1.35 kB
import _includes from "lodash/fp/includes"; import _find from "lodash/fp/find"; 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