diff options
Diffstat (limited to 'devtools/client/responsive.html/reducers')
8 files changed, 365 insertions, 0 deletions
diff --git a/devtools/client/responsive.html/reducers/devices.js b/devtools/client/responsive.html/reducers/devices.js new file mode 100644 index 000000000..e78632b24 --- /dev/null +++ b/devtools/client/responsive.html/reducers/devices.js @@ -0,0 +1,86 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { + ADD_DEVICE, + ADD_DEVICE_TYPE, + LOAD_DEVICE_LIST_START, + LOAD_DEVICE_LIST_ERROR, + LOAD_DEVICE_LIST_END, + UPDATE_DEVICE_DISPLAYED, + UPDATE_DEVICE_MODAL_OPEN, +} = require("../actions/index"); + +const Types = require("../types"); + +const INITIAL_DEVICES = { + types: [], + isModalOpen: false, + listState: Types.deviceListState.INITIALIZED, +}; + +let reducers = { + + [ADD_DEVICE](devices, { device, deviceType }) { + return Object.assign({}, devices, { + [deviceType]: [...devices[deviceType], device], + }); + }, + + [ADD_DEVICE_TYPE](devices, { deviceType }) { + return Object.assign({}, devices, { + types: [...devices.types, deviceType], + [deviceType]: [], + }); + }, + + [UPDATE_DEVICE_DISPLAYED](devices, { device, deviceType, displayed }) { + let newDevices = devices[deviceType].map(d => { + if (d == device) { + d.displayed = displayed; + } + + return d; + }); + + return Object.assign({}, devices, { + [deviceType]: newDevices, + }); + }, + + [LOAD_DEVICE_LIST_START](devices, action) { + return Object.assign({}, devices, { + listState: Types.deviceListState.LOADING, + }); + }, + + [LOAD_DEVICE_LIST_ERROR](devices, action) { + return Object.assign({}, devices, { + listState: Types.deviceListState.ERROR, + }); + }, + + [LOAD_DEVICE_LIST_END](devices, action) { + return Object.assign({}, devices, { + listState: Types.deviceListState.LOADED, + }); + }, + + [UPDATE_DEVICE_MODAL_OPEN](devices, { isOpen }) { + return Object.assign({}, devices, { + isModalOpen: isOpen, + }); + }, + +}; + +module.exports = function (devices = INITIAL_DEVICES, action) { + let reducer = reducers[action.type]; + if (!reducer) { + return devices; + } + return reducer(devices, action); +}; diff --git a/devtools/client/responsive.html/reducers/display-pixel-ratio.js b/devtools/client/responsive.html/reducers/display-pixel-ratio.js new file mode 100644 index 000000000..3f127c206 --- /dev/null +++ b/devtools/client/responsive.html/reducers/display-pixel-ratio.js @@ -0,0 +1,26 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* eslint-env browser */ + +"use strict"; + +const { CHANGE_DISPLAY_PIXEL_RATIO } = require("../actions/index"); +const INITIAL_DISPLAY_PIXEL_RATIO = 0; + +let reducers = { + + [CHANGE_DISPLAY_PIXEL_RATIO](_, action) { + return action.displayPixelRatio; + }, + +}; + +module.exports = function (displayPixelRatio = INITIAL_DISPLAY_PIXEL_RATIO, action) { + let reducer = reducers[action.type]; + if (!reducer) { + return displayPixelRatio; + } + return reducer(displayPixelRatio, action); +}; diff --git a/devtools/client/responsive.html/reducers/location.js b/devtools/client/responsive.html/reducers/location.js new file mode 100644 index 000000000..2063c9776 --- /dev/null +++ b/devtools/client/responsive.html/reducers/location.js @@ -0,0 +1,25 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { CHANGE_LOCATION } = require("../actions/index"); + +const INITIAL_LOCATION = "about:blank"; + +let reducers = { + + [CHANGE_LOCATION](_, action) { + return action.location; + }, + +}; + +module.exports = function (location = INITIAL_LOCATION, action) { + let reducer = reducers[action.type]; + if (!reducer) { + return location; + } + return reducer(location, action); +}; diff --git a/devtools/client/responsive.html/reducers/moz.build b/devtools/client/responsive.html/reducers/moz.build new file mode 100644 index 000000000..f1e9668f0 --- /dev/null +++ b/devtools/client/responsive.html/reducers/moz.build @@ -0,0 +1,15 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DevToolsModules( + 'devices.js', + 'display-pixel-ratio.js', + 'location.js', + 'network-throttling.js', + 'screenshot.js', + 'touch-simulation.js', + 'viewports.js', +) diff --git a/devtools/client/responsive.html/reducers/network-throttling.js b/devtools/client/responsive.html/reducers/network-throttling.js new file mode 100644 index 000000000..f892553c1 --- /dev/null +++ b/devtools/client/responsive.html/reducers/network-throttling.js @@ -0,0 +1,33 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { + CHANGE_NETWORK_THROTTLING, +} = require("../actions/index"); + +const INITIAL_NETWORK_THROTTLING = { + enabled: false, + profile: "", +}; + +let reducers = { + + [CHANGE_NETWORK_THROTTLING](throttling, { enabled, profile }) { + return { + enabled, + profile, + }; + }, + +}; + +module.exports = function (throttling = INITIAL_NETWORK_THROTTLING, action) { + let reducer = reducers[action.type]; + if (!reducer) { + return throttling; + } + return reducer(throttling, action); +}; diff --git a/devtools/client/responsive.html/reducers/screenshot.js b/devtools/client/responsive.html/reducers/screenshot.js new file mode 100644 index 000000000..9d24d8c5b --- /dev/null +++ b/devtools/client/responsive.html/reducers/screenshot.js @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { + TAKE_SCREENSHOT_END, + TAKE_SCREENSHOT_START, +} = require("../actions/index"); + +const INITIAL_SCREENSHOT = { isCapturing: false }; + +let reducers = { + + [TAKE_SCREENSHOT_END](screenshot, action) { + return Object.assign({}, screenshot, { isCapturing: false }); + }, + + [TAKE_SCREENSHOT_START](screenshot, action) { + return Object.assign({}, screenshot, { isCapturing: true }); + }, +}; + +module.exports = function (screenshot = INITIAL_SCREENSHOT, action) { + let reducer = reducers[action.type]; + if (!reducer) { + return screenshot; + } + return reducer(screenshot, action); +}; diff --git a/devtools/client/responsive.html/reducers/touch-simulation.js b/devtools/client/responsive.html/reducers/touch-simulation.js new file mode 100644 index 000000000..b3203b644 --- /dev/null +++ b/devtools/client/responsive.html/reducers/touch-simulation.js @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { + CHANGE_TOUCH_SIMULATION, +} = require("../actions/index"); + +const INITIAL_TOUCH_SIMULATION = { + enabled: false, +}; + +let reducers = { + + [CHANGE_TOUCH_SIMULATION](touchSimulation, { enabled }) { + return Object.assign({}, touchSimulation, { + enabled, + }); + }, + +}; + +module.exports = function (touchSimulation = INITIAL_TOUCH_SIMULATION, action) { + let reducer = reducers[action.type]; + if (!reducer) { + return touchSimulation; + } + return reducer(touchSimulation, action); +}; diff --git a/devtools/client/responsive.html/reducers/viewports.js b/devtools/client/responsive.html/reducers/viewports.js new file mode 100644 index 000000000..ee130ceaf --- /dev/null +++ b/devtools/client/responsive.html/reducers/viewports.js @@ -0,0 +1,118 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { + ADD_VIEWPORT, + CHANGE_DEVICE, + CHANGE_PIXEL_RATIO, + REMOVE_DEVICE, + RESIZE_VIEWPORT, + ROTATE_VIEWPORT, +} = require("../actions/index"); + +let nextViewportId = 0; + +const INITIAL_VIEWPORTS = []; +const INITIAL_VIEWPORT = { + id: nextViewportId++, + device: "", + width: 320, + height: 480, + pixelRatio: { + value: 0, + }, +}; + +let reducers = { + + [ADD_VIEWPORT](viewports) { + // For the moment, there can be at most one viewport. + if (viewports.length === 1) { + return viewports; + } + return [...viewports, Object.assign({}, INITIAL_VIEWPORT)]; + }, + + [CHANGE_DEVICE](viewports, { id, device }) { + return viewports.map(viewport => { + if (viewport.id !== id) { + return viewport; + } + + return Object.assign({}, viewport, { + device, + }); + }); + }, + + [CHANGE_PIXEL_RATIO](viewports, { id, pixelRatio }) { + return viewports.map(viewport => { + if (viewport.id !== id) { + return viewport; + } + + return Object.assign({}, viewport, { + pixelRatio: { + value: pixelRatio + }, + }); + }); + }, + + [REMOVE_DEVICE](viewports, { id }) { + return viewports.map(viewport => { + if (viewport.id !== id) { + return viewport; + } + + return Object.assign({}, viewport, { + device: "", + }); + }); + }, + + [RESIZE_VIEWPORT](viewports, { id, width, height }) { + return viewports.map(viewport => { + if (viewport.id !== id) { + return viewport; + } + + if (!width) { + width = viewport.width; + } + if (!height) { + height = viewport.height; + } + + return Object.assign({}, viewport, { + width, + height, + }); + }); + }, + + [ROTATE_VIEWPORT](viewports, { id }) { + return viewports.map(viewport => { + if (viewport.id !== id) { + return viewport; + } + + return Object.assign({}, viewport, { + width: viewport.height, + height: viewport.width, + }); + }); + }, + +}; + +module.exports = function (viewports = INITIAL_VIEWPORTS, action) { + let reducer = reducers[action.type]; + if (!reducer) { + return viewports; + } + return reducer(viewports, action); +}; |