UNPKG

kibana-123

Version:

Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic

46 lines (39 loc) 1.12 kB
import { includes, mapValues } from 'lodash'; import Notifier from 'ui/notify/notifier'; /* * Caches notification attempts so each one is only actually sent to the * notifier service once per route. */ export default function routeBasedNotifierProvider($rootScope) { const notifier = new Notifier(); let notifications = { warnings: [] }; // empty the tracked notifications whenever the route changes so we can start // fresh for the next route cycle $rootScope.$on('$routeChangeSuccess', () => { notifications = mapValues(notifications, () => []); }); // Executes the given notify function if the message has not been seen in // this route cycle function executeIfNew(messages, message, notifyFn) { if (includes(messages, message)) { return; } messages.push(message); notifyFn.call(notifier, message); } return { /** * Notify a given warning once in this route cycle * @param {string} message */ warning(message) { executeIfNew( notifications.warnings, message, notifier.warning ); } }; };