page-state.js (754B)
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 5 "use strict"; 6 7 const { 8 UPDATE_DOMAIN, 9 } = require("resource://devtools/client/application/src/constants.js"); 10 11 function PageState() { 12 return { 13 // Domain 14 domain: null, 15 }; 16 } 17 18 function getDomainFromUrl(url) { 19 return new URL(url).hostname; 20 } 21 22 function pageReducer(state = PageState(), action) { 23 switch (action.type) { 24 case UPDATE_DOMAIN: { 25 const { url } = action; 26 return { 27 domain: getDomainFromUrl(url), 28 }; 29 } 30 31 default: 32 return state; 33 } 34 } 35 36 module.exports = { 37 PageState, 38 pageReducer, 39 };