Skip to content

Commit

Permalink
Bug 1721072 - Move isSupportedPlatform to the store initialization ac…
Browse files Browse the repository at this point in the history
…tion. r=canaltinova

This means that we don't need to mount the ProfilerEventHandling component to get this piece of information.

Differential Revision: https://phabricator.services.mozilla.com/D120154
  • Loading branch information
mstange committed Jul 22, 2021
1 parent cee8a05 commit dfba4c5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 13 deletions.
3 changes: 2 additions & 1 deletion devtools/client/performance-new/@types/perf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ export type Action =
}
| {
type: "REPORT_PROFILER_READY";
isSupportedPlatform: boolean;
recordingState: RecordingState;
}
| {
Expand All @@ -295,6 +294,7 @@ export type Action =
| {
type: "INITIALIZE_STORE";
perfFront: PerfFront;
isSupportedPlatform: boolean;
setRecordingSettings: SetRecordingSettings;
presets: Presets;
pageContext: PageContext;
Expand All @@ -310,6 +310,7 @@ export type Action =

export interface InitializeStoreValues {
perfFront: PerfFront;
isSupportedPlatform: boolean;
setRecordingSettings: SetRecordingSettings;
presets: Presets;
pageContext: PageContext;
Expand Down
2 changes: 2 additions & 0 deletions devtools/client/performance-new/aboutprofiling/initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const {
*/
async function gInit(perfFront, pageContext, openRemoteDevTools) {
const store = createStore(reducers);
const isSupportedPlatform = await perfFront.isSupportedPlatform();
const supportedFeatures = await perfFront.getSupportedFeatures();

const l10n = new FluentL10n();
Expand All @@ -104,6 +105,7 @@ async function gInit(perfFront, pageContext, openRemoteDevTools) {
store.dispatch(
actions.initializeStore({
perfFront,
isSupportedPlatform,
supportedFeatures,
presets,
// Get the preferences from the current browser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,14 @@ const selectors = require("devtools/client/performance-new/store/selectors");
*/
class ProfilerEventHandling extends PureComponent {
componentDidMount() {
const { perfFront, reportProfilerReady } = this.props;
const { perfFront, isSupportedPlatform, reportProfilerReady } = this.props;

// Ask for the initial state of the profiler.
Promise.all([
perfFront.isActive(),
perfFront.isSupportedPlatform(),
perfFront.isLockedForPrivateBrowsing(),
]).then(results => {
const [
isActive,
isSupportedPlatform,
isLockedForPrivateBrowsing,
] = results;
const [isActive, isLockedForPrivateBrowsing] = results;

let recordingState = this.props.recordingState;
// It's theoretically possible we got an event that already let us know about
Expand All @@ -78,7 +73,7 @@ class ProfilerEventHandling extends PureComponent {
recordingState = "available-to-record";
}
}
reportProfilerReady(isSupportedPlatform, recordingState);
reportProfilerReady(recordingState);
});

// Handle when the profiler changes state. It might be us, it might be someone else.
Expand Down
2 changes: 2 additions & 0 deletions devtools/client/performance-new/initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const {
*/
async function gInit(perfFront, pageContext, openAboutProfiling) {
const store = createStore(reducers);
const isSupportedPlatform = await perfFront.isSupportedPlatform();
const supportedFeatures = await perfFront.getSupportedFeatures();

if (!openAboutProfiling) {
Expand Down Expand Up @@ -120,6 +121,7 @@ async function gInit(perfFront, pageContext, openAboutProfiling) {
store.dispatch(
actions.initializeStore({
perfFront,
isSupportedPlatform,
recordingSettings: getRecordingSettings(pageContext, supportedFeatures),
presets,
supportedFeatures,
Expand Down
4 changes: 1 addition & 3 deletions devtools/client/performance-new/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ const changeRecordingState = (exports.changeRecordingState = (
/**
* This is the result of the initial questions about the state of the profiler.
*
* @param {boolean} isSupportedPlatform - This is a supported platform.
* @param {RecordingState} recordingState - A valid state in `recordingState`.
* @return {Action}
*/
exports.reportProfilerReady = (isSupportedPlatform, recordingState) => ({
exports.reportProfilerReady = recordingState => ({
type: "REPORT_PROFILER_READY",
isSupportedPlatform,
recordingState,
});

Expand Down
2 changes: 1 addition & 1 deletion devtools/client/performance-new/store/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function recordingUnexpectedlyStopped(state = false, action) {
*/
function isSupportedPlatform(state = null, action) {
switch (action.type) {
case "REPORT_PROFILER_READY":
case "INITIALIZE_STORE":
return action.isSupportedPlatform;
default:
return state;
Expand Down

0 comments on commit dfba4c5

Please sign in to comment.