UNPKG

@snipsonian/observable-state

Version:

Observable-state snippets (redux-like)

25 lines (24 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEFAULT_PARENT_NOTIFICATIONS_DELIMITER = exports.DEFAULT_NR_OF_PARENT_NOTIFICATION_LEVELS_TO_TRIGGER = void 0; exports.DEFAULT_NR_OF_PARENT_NOTIFICATION_LEVELS_TO_TRIGGER = 1; exports.DEFAULT_PARENT_NOTIFICATIONS_DELIMITER = '.'; function extendNotificationsToTrigger({ notificationsToTrigger, triggerParentNotifications = {}, }) { const { nrOfLevels = exports.DEFAULT_NR_OF_PARENT_NOTIFICATION_LEVELS_TO_TRIGGER, notificationDelimiter = exports.DEFAULT_PARENT_NOTIFICATIONS_DELIMITER, } = triggerParentNotifications; if (nrOfLevels >= 1 && notificationsToTrigger && notificationsToTrigger.length > 0) { return notificationsToTrigger .reduce((accumulator, notificationToTrigger) => { accumulator.push(notificationToTrigger); const parts = notificationToTrigger.split(notificationDelimiter); let counter = 0; while (counter < nrOfLevels && parts && parts.length > 1) { parts.pop(); accumulator.push(parts.join(notificationDelimiter)); counter += 1; } return accumulator; }, []); } return notificationsToTrigger; } exports.default = extendNotificationsToTrigger;