Skip to content

Commit 43598cf

Browse files
rschristiandevelopitcolinaaa
authored
chore: Backport refcallback type and debug helpers (#4860)
* fix: Backport RefCallback type change for cleanups Co-authored-by: Jason Miller <[email protected]> * feat: Backport exporting of helper function from debug Co-authored-by: Qingyu Wang <[email protected]> --------- Co-authored-by: Jason Miller <[email protected]> Co-authored-by: Qingyu Wang <[email protected]>
1 parent 6fea157 commit 43598cf

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

debug/src/index.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
import { VNode } from 'preact';
2+
3+
/**
4+
* Get the currently rendered `vnode`
5+
*/
6+
export function getCurrentVNode(): VNode | null;
7+
8+
/**
9+
* Return the component stack that was captured up to this point.
10+
*/
11+
export function getOwnerStack(vnode: VNode): string;
12+
13+
/**
14+
* Setup code to capture the component trace while rendering. Note that
15+
* we cannot simply traverse `vnode._parent` upwards, because we have some
16+
* debug messages for `this.setState` where the `vnode` is `undefined`.
17+
*/
18+
export function setupComponentStack(): void;
19+
120
/**
221
* Reset the history of which prop type warnings have been logged.
322
*/

debug/src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ import 'preact/devtools';
44
initDebug();
55

66
export { resetPropWarnings } from './check-props';
7+
8+
export {
9+
getCurrentVNode,
10+
getDisplayName,
11+
getOwnerStack
12+
} from './component-stack';

src/index-5.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface VNode<P = {}> {
3838
export type Key = string | number | any;
3939

4040
export type RefObject<T> = { current: T | null };
41-
export type RefCallback<T> = (instance: T | null) => void;
41+
export type RefCallback<T> = (instance: T | null) => void | (() => void);
4242
export type Ref<T> = RefObject<T> | RefCallback<T> | null;
4343

4444
export type ComponentChild =

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface VNode<P = {}> {
3838
export type Key = string | number | any;
3939

4040
export type RefObject<T> = { current: T | null };
41-
export type RefCallback<T> = (instance: T | null) => void;
41+
export type RefCallback<T> = (instance: T | null) => void | (() => void);
4242
export type Ref<T> = RefObject<T> | RefCallback<T> | null;
4343

4444
export type ComponentChild =

0 commit comments

Comments
 (0)