-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[react devtools][easy] Change function names and remove unused functions, add constants, etc #25211
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,16 +34,14 @@ import { | |
TREE_OPERATION_SET_SUBTREE_MODE, | ||
TREE_OPERATION_UPDATE_ERRORS_OR_WARNINGS, | ||
TREE_OPERATION_UPDATE_TREE_BASE_DURATION, | ||
} from './constants'; | ||
import {ElementTypeRoot} from 'react-devtools-shared/src/types'; | ||
import { | ||
LOCAL_STORAGE_FILTER_PREFERENCES_KEY, | ||
LOCAL_STORAGE_COMPONENT_FILTER_PREFERENCES_KEY, | ||
LOCAL_STORAGE_OPEN_IN_EDITOR_URL, | ||
LOCAL_STORAGE_SHOULD_BREAK_ON_CONSOLE_ERRORS, | ||
LOCAL_STORAGE_SHOULD_APPEND_COMPONENT_STACK_KEY, | ||
LOCAL_STORAGE_SHOW_INLINE_WARNINGS_AND_ERRORS_KEY, | ||
LOCAL_STORAGE_HIDE_CONSOLE_LOGS_IN_STRICT_MODE, | ||
} from './constants'; | ||
import {ElementTypeRoot} from 'react-devtools-shared/src/types'; | ||
import {ComponentFilterElementType, ElementTypeHostComponent} from './types'; | ||
import { | ||
ElementTypeClass, | ||
|
@@ -324,97 +322,58 @@ export function getDefaultComponentFilters(): Array<ComponentFilter> { | |
|
||
export function getSavedComponentFilters(): Array<ComponentFilter> { | ||
try { | ||
const raw = localStorageGetItem(LOCAL_STORAGE_FILTER_PREFERENCES_KEY); | ||
const raw = localStorageGetItem( | ||
LOCAL_STORAGE_COMPONENT_FILTER_PREFERENCES_KEY, | ||
); | ||
if (raw != null) { | ||
return JSON.parse(raw); | ||
} | ||
} catch (error) {} | ||
return getDefaultComponentFilters(); | ||
} | ||
|
||
export function saveComponentFilters( | ||
export function setSavedComponentFilters( | ||
componentFilters: Array<ComponentFilter>, | ||
): void { | ||
localStorageSetItem( | ||
LOCAL_STORAGE_FILTER_PREFERENCES_KEY, | ||
LOCAL_STORAGE_COMPONENT_FILTER_PREFERENCES_KEY, | ||
JSON.stringify(componentFilters), | ||
); | ||
} | ||
|
||
export function getAppendComponentStack(): boolean { | ||
try { | ||
const raw = localStorageGetItem( | ||
LOCAL_STORAGE_SHOULD_APPEND_COMPONENT_STACK_KEY, | ||
); | ||
if (raw != null) { | ||
return JSON.parse(raw); | ||
} | ||
} catch (error) {} | ||
return true; | ||
function parseBool(s: ?string): ?boolean { | ||
if (s === 'true') { | ||
return true; | ||
} | ||
if (s === 'false') { | ||
return false; | ||
} | ||
} | ||
|
||
export function setAppendComponentStack(value: boolean): void { | ||
localStorageSetItem( | ||
export function getAppendComponentStack(): boolean { | ||
const raw = localStorageGetItem( | ||
LOCAL_STORAGE_SHOULD_APPEND_COMPONENT_STACK_KEY, | ||
JSON.stringify(value), | ||
); | ||
return parseBool(raw) ?? true; | ||
} | ||
|
||
export function getBreakOnConsoleErrors(): boolean { | ||
try { | ||
const raw = localStorageGetItem( | ||
LOCAL_STORAGE_SHOULD_BREAK_ON_CONSOLE_ERRORS, | ||
); | ||
if (raw != null) { | ||
return JSON.parse(raw); | ||
} | ||
} catch (error) {} | ||
return false; | ||
} | ||
|
||
export function setBreakOnConsoleErrors(value: boolean): void { | ||
localStorageSetItem( | ||
LOCAL_STORAGE_SHOULD_BREAK_ON_CONSOLE_ERRORS, | ||
JSON.stringify(value), | ||
); | ||
const raw = localStorageGetItem(LOCAL_STORAGE_SHOULD_BREAK_ON_CONSOLE_ERRORS); | ||
return parseBool(raw) ?? false; | ||
} | ||
|
||
export function getHideConsoleLogsInStrictMode(): boolean { | ||
try { | ||
const raw = localStorageGetItem( | ||
LOCAL_STORAGE_HIDE_CONSOLE_LOGS_IN_STRICT_MODE, | ||
); | ||
if (raw != null) { | ||
return JSON.parse(raw); | ||
} | ||
} catch (error) {} | ||
return false; | ||
} | ||
|
||
export function sethideConsoleLogsInStrictMode(value: boolean): void { | ||
localStorageSetItem( | ||
const raw = localStorageGetItem( | ||
LOCAL_STORAGE_HIDE_CONSOLE_LOGS_IN_STRICT_MODE, | ||
JSON.stringify(value), | ||
); | ||
return parseBool(raw) ?? false; | ||
} | ||
|
||
export function getShowInlineWarningsAndErrors(): boolean { | ||
try { | ||
const raw = localStorageGetItem( | ||
LOCAL_STORAGE_SHOW_INLINE_WARNINGS_AND_ERRORS_KEY, | ||
); | ||
if (raw != null) { | ||
return JSON.parse(raw); | ||
} | ||
} catch (error) {} | ||
return true; | ||
} | ||
|
||
export function setShowInlineWarningsAndErrors(value: boolean): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you remove this you can probably also remove the other setters since they're also not used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I removed all the unused setters 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only one of the setters was used, and it was used in |
||
localStorageSetItem( | ||
const raw = localStorageGetItem( | ||
LOCAL_STORAGE_SHOW_INLINE_WARNINGS_AND_ERRORS_KEY, | ||
JSON.stringify(value), | ||
); | ||
return parseBool(raw) ?? true; | ||
} | ||
|
||
export function getDefaultOpenInEditorURL(): string { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably don't need the
parseBool
method (might create unnecessary indirection that might make the code more confusing) What do you think about removingparseBool
and replacing it with something like:return typeof raw === 'string' && raw === 'false' ? false : true;