From e8f84dd5c4d02ca8278d57e0d1406ff075a7ffb1 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 15 Mar 2019 08:34:08 -0700 Subject: [PATCH] Iterating on Profiling tab suspense. Stashing changes but planning to refactor immediately. --- src/devtools/store.js | 10 +- src/devtools/views/Profiler/FilterModal.js | 25 +-- src/devtools/views/Profiler/Profiler.js | 25 ++- .../views/Profiler/ProfilerContext.js | 149 ------------------ .../views/Profiler/ProfilerDataContext.js | 94 +++++++++++ .../views/Profiler/ProfilerStatusContext.js | 69 ++++++++ src/devtools/views/Profiler/RecordToggle.js | 4 +- .../views/Profiler/SnapshotCommitList.js | 72 ++++----- .../views/Profiler/SnapshotCommitListItem.js | 7 +- .../views/Profiler/SnapshotSelector.js | 99 ++++-------- src/devtools/views/TabBar.css | 7 +- src/devtools/views/hooks.js | 42 +++-- 12 files changed, 309 insertions(+), 294 deletions(-) delete mode 100644 src/devtools/views/Profiler/ProfilerContext.js create mode 100644 src/devtools/views/Profiler/ProfilerDataContext.js create mode 100644 src/devtools/views/Profiler/ProfilerStatusContext.js diff --git a/src/devtools/store.js b/src/devtools/store.js index c1fe80ebbe..ba731a0fd1 100644 --- a/src/devtools/store.js +++ b/src/devtools/store.js @@ -275,16 +275,24 @@ export default class Store extends EventEmitter { } startProfiling(): void { + this._bridge.send('startProfiling'); + // Invalidate suspense cache if profiling data is being (re-)recorded. + // Note that we clear now because any existing data is "stale". this._profilingCache.invalidate(); - this._bridge.send('startProfiling'); this._isProfiling = false; this.emit('isProfiling'); } stopProfiling(): void { this._bridge.send('stopProfiling'); + + // Invalidate suspense cache if profiling data is being (re-)recorded. + // Note that we clear again, in case any views read from the cache while profiling. + // (That would have resolved a now-stale value without any profiling data.) + this._profilingCache.invalidate(); + this._isProfiling = false; this.emit('isProfiling'); } diff --git a/src/devtools/views/Profiler/FilterModal.js b/src/devtools/views/Profiler/FilterModal.js index 8e91ef0a0d..085fee0a7f 100644 --- a/src/devtools/views/Profiler/FilterModal.js +++ b/src/devtools/views/Profiler/FilterModal.js @@ -1,8 +1,7 @@ // @flow -import React, { useCallback, useContext, useEffect, useRef } from 'react'; -import { useModalDismissSignal } from '../hooks'; -import { ProfilerContext } from './ProfilerContext'; +import React, { useCallback, useEffect, useRef } from 'react'; +import { useLocalStorage, useModalDismissSignal } from '../hooks'; import styles from './FilterModal.css'; @@ -11,12 +10,14 @@ type Props = {| |}; export default function FilterModal({ dismissModal }: Props) { - const { - isMinCommitDurationEnabled, - minCommitDuration, - setMinCommitDuration, - setIsMinCommitDurationEnabled, - } = useContext(ProfilerContext); + const [ + isCommitFilterEnabled, + setIsCommitFilterEnabled, + ] = useLocalStorage('isCommitFilterEnabled', false); + const [minCommitDuration, setMinCommitDuration] = useLocalStorage( + 'minCommitDuration', + 0 + ); const handleNumberChange = useCallback( ({ currentTarget }) => { @@ -30,14 +31,14 @@ export default function FilterModal({ dismissModal }: Props) { const handleEnabledChange = useCallback( ({ currentTarget }) => { - setIsMinCommitDurationEnabled(currentTarget.checked); + setIsCommitFilterEnabled(currentTarget.checked); if (currentTarget.checked) { if (inputRef.current !== null) { inputRef.current.focus(); } } }, - [setIsMinCommitDurationEnabled] + [setIsCommitFilterEnabled] ); const inputRef = useRef(null); @@ -56,7 +57,7 @@ export default function FilterModal({ dismissModal }: Props) {