mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 11:41:44 +00:00
[react] RE: Add unstable_Profiler (#34253)
* feat(react): Add unstable_Profiler * OnRenderCallback -> ProfilerOnRenderCallback OnRenderCallback is to generic * Interaction -> SchedulerInteraction It's actually part of scheduler/tracing
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
f2750d5585
commit
7d483f04fe
Vendored
+30
@@ -22,6 +22,7 @@
|
||||
// Paul Sherman <https://github.com/pshrmn>
|
||||
// Saransh Kataria <https://github.com/saranshkataria>
|
||||
// Kanitkorn Sujautra <https://github.com/lukyth>
|
||||
// Sebastian Silbermann <https://github.com/eps1lon>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
@@ -43,6 +44,15 @@ type NativeTransitionEvent = TransitionEvent;
|
||||
type NativeUIEvent = UIEvent;
|
||||
type NativeWheelEvent = WheelEvent;
|
||||
|
||||
/**
|
||||
* defined in scheduler/tracing
|
||||
*/
|
||||
interface SchedulerInteraction {
|
||||
id: number;
|
||||
name: string;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:export-just-namespace
|
||||
export = React;
|
||||
export as namespace React;
|
||||
@@ -356,6 +366,26 @@ declare namespace React {
|
||||
const Suspense: ExoticComponent<SuspenseProps>;
|
||||
const version: string;
|
||||
|
||||
/**
|
||||
* {@link https://github.com/bvaughn/rfcs/blob/profiler/text/0000-profiler.md#detailed-design | API}
|
||||
*/
|
||||
type ProfilerOnRenderCallback = (
|
||||
id: string,
|
||||
phase: "mount" | "update",
|
||||
actualDuration: number,
|
||||
baseDuration: number,
|
||||
startTime: number,
|
||||
commitTime: number,
|
||||
interactions: Set<SchedulerInteraction>,
|
||||
) => void;
|
||||
interface ProfilerProps {
|
||||
children?: ReactNode;
|
||||
id: string;
|
||||
onRender: ProfilerOnRenderCallback;
|
||||
}
|
||||
|
||||
const unstable_Profiler: ExoticComponent<ProfilerProps>;
|
||||
|
||||
//
|
||||
// Component API
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@@ -321,6 +321,41 @@ const ForwardRef3 = React.forwardRef(
|
||||
<ForwardRef3 ref={divFnRef}/>;
|
||||
<ForwardRef3 ref={divRef}/>;
|
||||
|
||||
const Profiler = React.unstable_Profiler;
|
||||
|
||||
// 'id' is missing
|
||||
<Profiler />; // $ExpectError
|
||||
// 'onRender' is missing
|
||||
<Profiler id="test" />; // $ExpectError
|
||||
// 'number' is not assignable to 'string'
|
||||
<Profiler id={2} />; // $ExpectError
|
||||
|
||||
<Profiler
|
||||
id="test"
|
||||
onRender={(
|
||||
id,
|
||||
phase,
|
||||
actualDuration,
|
||||
baseDuration,
|
||||
startTime,
|
||||
commitTime,
|
||||
interactions
|
||||
) => {
|
||||
const message = `${id} ${phase} took ${actualDuration.toFixed(2)}s actual, ${baseDuration.toFixed(2)}s base`;
|
||||
|
||||
const commitMessage = `commit started ${startTime.toFixed(2)} within ${commitTime}`;
|
||||
|
||||
const interactionsSummary = Array.from(interactions)
|
||||
.map(interaction => {
|
||||
return `${interaction.id}: '${interaction.name}' started at ${interaction.timestamp.toFixed(2)}`;
|
||||
})
|
||||
.join("\n");
|
||||
const interactionMessage = `there were ${interactions.size} interactions:\n${interactionsSummary}`;
|
||||
}}
|
||||
>
|
||||
<div />
|
||||
</Profiler>;
|
||||
|
||||
type ImgProps = React.ComponentProps<'img'>;
|
||||
// $ExpectType "async" | "auto" | "sync" | undefined
|
||||
type ImgPropsDecoding = ImgProps['decoding'];
|
||||
|
||||
Reference in New Issue
Block a user