UNPKG

@snipsonian/observable-state

Version:

Observable-state snippets (redux-like)

21 lines (20 loc) 1.07 kB
export const DEFAULT_NR_OF_PARENT_NOTIFICATION_LEVELS_TO_TRIGGER = 1; export const DEFAULT_PARENT_NOTIFICATIONS_DELIMITER = '.'; export default function extendNotificationsToTrigger({ notificationsToTrigger, triggerParentNotifications = {}, }) { const { nrOfLevels = DEFAULT_NR_OF_PARENT_NOTIFICATION_LEVELS_TO_TRIGGER, notificationDelimiter = 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; }