Skip to content

Commit 44c20c6

Browse files
committed
Updated to account for facebook/react/pull/14906/commits/cdd9ba4
1 parent 81b08de commit 44c20c6

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

src/backend/ReactDebugHooks.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ type ReactCurrentDispatcher = {
225225
};
226226

227227
type HooksNode = {
228-
index: number,
229-
isEditable: boolean,
228+
id: number | null,
229+
isStateEditable: boolean,
230230
name: string,
231231
value: mixed,
232232
subHooks: Array<HooksNode>,
@@ -368,7 +368,7 @@ function buildTree(rootStack, readHookLog): HooksTree {
368368
const rootChildren = [];
369369
let prevStack = null;
370370
let levelChildren = rootChildren;
371-
let index = 0;
371+
let nativeHookID = 0;
372372
const stackOfChildren = [];
373373
for (let i = 0; i < readHookLog.length; i++) {
374374
const hook = readHookLog[i];
@@ -402,8 +402,8 @@ function buildTree(rootStack, readHookLog): HooksTree {
402402
levelChildren.push({
403403
name: parseCustomHookName(stack[j - 1].functionName),
404404
value: undefined,
405-
index: -1,
406-
isEditable: false,
405+
id: null,
406+
isStateEditable: false,
407407
subHooks: children,
408408
});
409409
stackOfChildren.push(levelChildren);
@@ -412,9 +412,20 @@ function buildTree(rootStack, readHookLog): HooksTree {
412412
prevStack = stack;
413413
}
414414
const { primitive } = hook;
415+
416+
// For now, the "id" of stateful hooks is just the stateful hook index.
417+
// Custom hooks have no ids, nor do non-stateful native hooks (e.g. Context, DebugValue).
418+
const id =
419+
primitive === 'Context' || primitive === 'DebugValue'
420+
? null
421+
: nativeHookID++;
422+
423+
// For the time being, only State and Reducer hooks support runtime overrides.
424+
const isStateEditable = primitive === 'Reducer' || primitive === 'State';
425+
415426
levelChildren.push({
416-
index: primitive === 'DebugValue' ? -1 : index++,
417-
isEditable: primitive === 'Reducer' || primitive === 'State',
427+
id,
428+
isStateEditable,
418429
name: primitive,
419430
value: hook.value,
420431
subHooks: [],

src/backend/agent.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type InspectSelectParams = {|
2525

2626
type OverrideHookParams = {|
2727
id: number,
28-
index: number,
28+
hookID: number,
2929
path: Array<string | number>,
3030
rendererID: number,
3131
value: any,
@@ -134,7 +134,7 @@ export default class Agent extends EventEmitter {
134134

135135
overrideHookState = ({
136136
id,
137-
index,
137+
hookID,
138138
path,
139139
rendererID,
140140
value,
@@ -143,7 +143,7 @@ export default class Agent extends EventEmitter {
143143
if (renderer == null) {
144144
console.warn(`Invalid renderer id "${rendererID}" for element "${id}"`);
145145
} else {
146-
renderer.setInHook(id, index, path, value);
146+
renderer.setInHook(id, hookID, path, value);
147147
}
148148
};
149149

src/backend/types.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ export type DevToolsHook = {
100100
};
101101

102102
export type HooksNode = {
103-
index: number,
104-
isEditable: boolean,
103+
id: number,
104+
isStateEditable: boolean,
105105
name: string,
106106
value: mixed,
107107
subHooks: Array<HooksNode>,

src/devtools/views/HooksTree.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type HookViewProps = {|
7070
|};
7171

7272
function HookView({ canEditHooks, hook, id, path = [] }: HookViewProps) {
73-
const { name, index, isEditable, subHooks, value } = hook;
73+
const { name, id: hookID, isStateEditable, subHooks, value } = hook;
7474

7575
const bridge = useContext(BridgeContext);
7676
const store = useContext(StoreContext);
@@ -141,12 +141,12 @@ function HookView({ canEditHooks, hook, id, path = [] }: HookViewProps) {
141141
} else {
142142
let overrideValueFn = null;
143143
// TODO Maybe read editable value from debug hook?
144-
if (canEditHooks && isEditable) {
144+
if (canEditHooks && isStateEditable) {
145145
overrideValueFn = (path: Array<string | number>, value: any) => {
146146
const rendererID = store.getRendererIDForElement(id);
147147
bridge.send('overrideHookState', {
148148
id,
149-
index,
149+
hookID,
150150
path,
151151
rendererID,
152152
value,

src/devtools/views/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export function serializeHooksForCopy(hooks: HooksTree | null): string {
7070
const current = queue.pop();
7171

7272
// These aren't meaningful
73-
delete current.isEditable;
74-
delete current.index;
73+
delete current.id;
74+
delete current.isStateEditable;
7575

7676
if (current.subHooks.length > 0) {
7777
queue.push(...current.subHooks);

0 commit comments

Comments
 (0)