Bug 1566007 - Part 1: Create Redux state/reducers/actions to hold manifest data r=Ola

Differential Revision: https://phabricator.services.mozilla.com/D41973

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Belén Albeza 2019-08-15 08:32:25 +00:00
parent cf0604278c
commit fa01c1cf25
9 changed files with 84 additions and 2 deletions

View File

@ -7,5 +7,6 @@
const workers = require("./workers");
const page = require("./page");
const ui = require("./ui");
const manifest = require("./manifest");
Object.assign(exports, workers, page, ui);
Object.assign(exports, workers, page, ui, manifest);

View File

@ -0,0 +1,19 @@
/* 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 { UPDATE_MANIFEST } = require("../constants");
function updateManifest(manifest, errorMessage) {
return {
type: UPDATE_MANIFEST,
manifest,
errorMessage,
};
}
module.exports = {
updateManifest,
};

View File

@ -4,6 +4,7 @@
DevToolsModules(
'index.js',
'manifest.js',
'page.js',
'ui.js',
'workers.js',

View File

@ -5,6 +5,8 @@
"use strict";
const actionTypes = {
// manifest substate
UPDATE_MANIFEST: "UPDATE_MANIFEST",
// page substate
UPDATE_DOMAIN: "UPDATE_DOMAIN",
// ui substate

View File

@ -8,9 +8,11 @@ const { combineReducers } = require("devtools/client/shared/vendor/redux");
const { workersReducer } = require("./workers-state");
const { pageReducer } = require("./page-state");
const { uiReducer } = require("./ui-state");
const { manifestReducer } = require("./manifest-state");
module.exports = combineReducers({
workers: workersReducer,
manifest: manifestReducer,
page: pageReducer,
workers: workersReducer,
ui: uiReducer,
});

View File

@ -0,0 +1,32 @@
/* 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 { UPDATE_MANIFEST } = require("../constants");
function ManifestState() {
return {
manifest: null,
errorMessage: "",
};
}
function manifestReducer(state = ManifestState(), action) {
switch (action.type) {
case UPDATE_MANIFEST:
const { manifest, errorMessage } = action;
return Object.assign({}, state, {
manifest,
errorMessage,
});
default:
return state;
}
}
module.exports = {
ManifestState,
manifestReducer,
};

View File

@ -4,6 +4,7 @@
DevToolsModules(
'index.js',
'manifest-state.js',
'page-state.js',
'ui-state.js',
'workers-state.js',

View File

@ -0,0 +1,23 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const {
updateManifest,
} = require("devtools/client/application/src/actions/manifest.js");
const {
manifestReducer,
ManifestState,
} = require("devtools/client/application/src/reducers/manifest-state.js");
add_task(async function() {
info("Test manifest reducer: UPDATE_MANIFEST action");
const state = ManifestState();
const action = updateManifest({ name: "foo" }, "some error");
const newState = manifestReducer(state, action);
equal(newState.manifest.name, "foo");
equal(newState.errorMessage, "some error");
});

View File

@ -4,6 +4,7 @@ head = xpcshell-head.js
firefox-appdir = browser
skip-if = toolkit == 'android'
[test_manifest_reducer.js]
[test_page_reducer.js]
[test_ui_reducer.js]
[test_workers_reducer.js]