UNPKG

@gechiui/nux

Version:
100 lines (81 loc) 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.areTipsEnabled = areTipsEnabled; exports.default = void 0; exports.dismissedTips = dismissedTips; exports.guides = guides; var _data = require("@gechiui/data"); /** * GeChiUI dependencies */ /** * Reducer that tracks which tips are in a guide. Each guide is represented by * an array which contains the tip identifiers contained within that guide. * * @param {Array} state Current state. * @param {Object} action Dispatched action. * * @return {Array} Updated state. */ function guides() { let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; let action = arguments.length > 1 ? arguments[1] : undefined; switch (action.type) { case 'TRIGGER_GUIDE': return [...state, action.tipIds]; } return state; } /** * Reducer that tracks whether or not tips are globally enabled. * * @param {boolean} state Current state. * @param {Object} action Dispatched action. * * @return {boolean} Updated state. */ function areTipsEnabled() { let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; let action = arguments.length > 1 ? arguments[1] : undefined; switch (action.type) { case 'DISABLE_TIPS': return false; case 'ENABLE_TIPS': return true; } return state; } /** * Reducer that tracks which tips have been dismissed. If the state object * contains a tip identifier, then that tip is dismissed. * * @param {Object} state Current state. * @param {Object} action Dispatched action. * * @return {Object} Updated state. */ function dismissedTips() { let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; let action = arguments.length > 1 ? arguments[1] : undefined; switch (action.type) { case 'DISMISS_TIP': return { ...state, [action.id]: true }; case 'ENABLE_TIPS': return {}; } return state; } const preferences = (0, _data.combineReducers)({ areTipsEnabled, dismissedTips }); var _default = (0, _data.combineReducers)({ guides, preferences }); exports.default = _default; //# sourceMappingURL=reducer.js.map