box-model.js (1090B)
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_GEOMETRY_EDITOR_ENABLED, 9 UPDATE_LAYOUT, 10 UPDATE_OFFSET_PARENT, 11 } = require("resource://devtools/client/inspector/boxmodel/actions/index.js"); 12 13 const INITIAL_BOX_MODEL = { 14 geometryEditorEnabled: false, 15 layout: {}, 16 offsetParent: null, 17 }; 18 19 const reducers = { 20 [UPDATE_GEOMETRY_EDITOR_ENABLED](boxModel, { enabled }) { 21 return Object.assign({}, boxModel, { 22 geometryEditorEnabled: enabled, 23 }); 24 }, 25 26 [UPDATE_LAYOUT](boxModel, { layout }) { 27 return Object.assign({}, boxModel, { 28 layout, 29 }); 30 }, 31 32 [UPDATE_OFFSET_PARENT](boxModel, { offsetParent }) { 33 return Object.assign({}, boxModel, { 34 offsetParent, 35 }); 36 }, 37 }; 38 39 module.exports = function (boxModel = INITIAL_BOX_MODEL, action) { 40 const reducer = reducers[action.type]; 41 if (!reducer) { 42 return boxModel; 43 } 44 return reducer(boxModel, action); 45 };