@wordpress/nux
Version:
NUX (New User eXperience) module for WordPress.
79 lines (75 loc) • 1.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.areTipsEnabled = areTipsEnabled;
exports.default = void 0;
exports.dismissedTips = dismissedTips;
exports.guides = guides;
var _data = require("@wordpress/data");
/**
* WordPress 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(state = [], action) {
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(state = true, action) {
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(state = {}, action) {
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 = exports.default = (0, _data.combineReducers)({
guides,
preferences
});
//# sourceMappingURL=reducer.js.map