Skip to content

Commit

Permalink
Bug 1515612 - Split PAGE_SELECTED action in START/SUCCESS/FAILURE sub…
Browse files Browse the repository at this point in the history
…actions;r=ladybenko,Ola

Depends on D15410

Differential Revision: https://phabricator.services.mozilla.com/D15414
  • Loading branch information
juliandescottes committed Jan 10, 2019
1 parent 04e94b1 commit 81b11dc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
56 changes: 32 additions & 24 deletions devtools/client/aboutdebugging-new/src/actions/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ const {
ADB_ADDON_STATUS_UPDATED,
DEBUG_TARGET_COLLAPSIBILITY_UPDATED,
NETWORK_LOCATIONS_UPDATED,
PAGE_SELECTED,
PAGE_TYPES,
SELECT_PAGE_FAILURE,
SELECT_PAGE_START,
SELECT_PAGE_SUCCESS,
USB_RUNTIMES_SCAN_START,
USB_RUNTIMES_SCAN_SUCCESS,
} = require("../constants");
Expand All @@ -28,33 +30,39 @@ const Actions = require("./index");

function selectPage(page, runtimeId) {
return async (dispatch, getState) => {
const isSamePage = (oldPage, newPage) => {
if (newPage === PAGE_TYPES.RUNTIME && oldPage === PAGE_TYPES.RUNTIME) {
return runtimeId === getState().runtimes.selectedRuntimeId;
dispatch({ type: SELECT_PAGE_START });

try {
const isSamePage = (oldPage, newPage) => {
if (newPage === PAGE_TYPES.RUNTIME && oldPage === PAGE_TYPES.RUNTIME) {
return runtimeId === getState().runtimes.selectedRuntimeId;
}
return newPage === oldPage;
};

const currentPage = getState().ui.selectedPage;
// Nothing to dispatch if the page is the same as the current page, or
// if we are not providing any page.
// TODO: we should dispatch SELECT_PAGE_FAILURE if page is missing. See Bug 1518559.
if (!page || isSamePage(currentPage, page)) {
return;
}
return newPage === oldPage;
};

const currentPage = getState().ui.selectedPage;
// Nothing to dispatch if the page is the same as the current page, or
// if we are not providing any page.
// Note: maybe we should have a PAGE_SELECTED_FAILURE action for proper logging
if (!page || isSamePage(currentPage, page)) {
return;
}

// Stop watching current runtime, if currently on a RUNTIME page.
if (currentPage === PAGE_TYPES.RUNTIME) {
const currentRuntimeId = getState().runtimes.selectedRuntimeId;
await dispatch(Actions.unwatchRuntime(currentRuntimeId));
}
// Stop watching current runtime, if currently on a RUNTIME page.
if (currentPage === PAGE_TYPES.RUNTIME) {
const currentRuntimeId = getState().runtimes.selectedRuntimeId;
await dispatch(Actions.unwatchRuntime(currentRuntimeId));
}

// Start watching current runtime, if moving to a RUNTIME page.
if (page === PAGE_TYPES.RUNTIME) {
await dispatch(Actions.watchRuntime(runtimeId));
}
// Start watching current runtime, if moving to a RUNTIME page.
if (page === PAGE_TYPES.RUNTIME) {
await dispatch(Actions.watchRuntime(runtimeId));
}

dispatch({ type: PAGE_SELECTED, page, runtimeId });
dispatch({ type: SELECT_PAGE_SUCCESS, page, runtimeId });
} catch (e) {
dispatch({ type: SELECT_PAGE_FAILURE, error: e });
}
};
}

Expand Down
4 changes: 3 additions & 1 deletion devtools/client/aboutdebugging-new/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const actionTypes = {
DISCONNECT_RUNTIME_START: "DISCONNECT_RUNTIME_START",
DISCONNECT_RUNTIME_SUCCESS: "DISCONNECT_RUNTIME_SUCCESS",
NETWORK_LOCATIONS_UPDATED: "NETWORK_LOCATIONS_UPDATED",
PAGE_SELECTED: "PAGE_SELECTED",
REMOTE_RUNTIMES_UPDATED: "REMOTE_RUNTIMES_UPDATED",
REQUEST_EXTENSIONS_FAILURE: "REQUEST_EXTENSIONS_FAILURE",
REQUEST_EXTENSIONS_START: "REQUEST_EXTENSIONS_START",
Expand All @@ -31,6 +30,9 @@ const actionTypes = {
REQUEST_WORKERS_FAILURE: "REQUEST_WORKERS_FAILURE",
REQUEST_WORKERS_START: "REQUEST_WORKERS_START",
REQUEST_WORKERS_SUCCESS: "REQUEST_WORKERS_SUCCESS",
SELECT_PAGE_FAILURE: "SELECT_PAGE_FAILURE",
SELECT_PAGE_START: "SELECT_PAGE_START",
SELECT_PAGE_SUCCESS: "SELECT_PAGE_SUCCESS",
TEMPORARY_EXTENSION_INSTALL_FAILURE: "TEMPORARY_EXTENSION_INSTALL_FAILURE",
TEMPORARY_EXTENSION_INSTALL_START: "TEMPORARY_EXTENSION_INSTALL_START",
TEMPORARY_EXTENSION_INSTALL_SUCCESS: "TEMPORARY_EXTENSION_INSTALL_SUCCESS",
Expand Down
4 changes: 2 additions & 2 deletions devtools/client/aboutdebugging-new/src/reducers/ui-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
ADB_ADDON_STATUS_UPDATED,
DEBUG_TARGET_COLLAPSIBILITY_UPDATED,
NETWORK_LOCATIONS_UPDATED,
PAGE_SELECTED,
SELECT_PAGE_SUCCESS,
TEMPORARY_EXTENSION_INSTALL_FAILURE,
TEMPORARY_EXTENSION_INSTALL_SUCCESS,
USB_RUNTIMES_SCAN_START,
Expand Down Expand Up @@ -51,7 +51,7 @@ function uiReducer(state = UiState(), action) {
return Object.assign({}, state, { networkLocations: locations });
}

case PAGE_SELECTED: {
case SELECT_PAGE_SUCCESS: {
const { page, runtimeId } = action;
return Object.assign({}, state,
{ selectedPage: page, selectedRuntime: runtimeId });
Expand Down

0 comments on commit 81b11dc

Please sign in to comment.