notifications.js (1359B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 "use strict"; 5 6 const { 7 APPEND_NOTIFICATION, 8 REMOVE_NOTIFICATION, 9 } = require("resource://devtools/client/webconsole/constants.js"); 10 11 loader.lazyRequireGetter( 12 this, 13 ["appendNotification", "removeNotificationWithValue"], 14 "resource://devtools/client/shared/components/NotificationBox.js", 15 true 16 ); 17 18 /** 19 * Create default initial state for this reducer. The state is composed 20 * from list of notifications. 21 */ 22 function getInitialState() { 23 return { 24 notifications: undefined, 25 }; 26 } 27 28 /** 29 * Reducer function implementation. This reducers is responsible 30 * for maintaining list of notifications. It's consumed by 31 * `NotificationBox` component. 32 */ 33 function notifications(state = getInitialState(), action) { 34 switch (action.type) { 35 case APPEND_NOTIFICATION: 36 return append(state, action); 37 case REMOVE_NOTIFICATION: 38 return remove(state, action); 39 } 40 41 return state; 42 } 43 44 // Helpers 45 46 function append(state, action) { 47 return appendNotification(state, action); 48 } 49 50 function remove(state, action) { 51 return removeNotificationWithValue(state.notifications, action.value); 52 } 53 54 // Exports 55 56 module.exports = { 57 notifications, 58 };