Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit b86c0f7

Browse files
2007heavennchevobbe
authored andcommitted
Use LongStringClient.substring to get fulltext
After a brief discussion in #1015 (#1015 (comment)), we decided that it'd be better to delegate client picking and invoking responsibilities to the `ObjectInspector`, by passing the `LongStringClient` creator to it (`WebConsoleClient.longString`).
1 parent 5a22c66 commit b86c0f7

File tree

5 files changed

+61
-28
lines changed

5 files changed

+61
-28
lines changed

packages/devtools-reps/src/object-inspector/actions.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
// @flow
66

77
import type {
8+
CreateLongStringClient,
9+
CreateObjectClient,
810
GripProperties,
911
LoadedProperties,
1012
Node,
11-
ObjectClient,
12-
RdpGrip,
1313
ReduxAction,
1414
} from "./types";
1515

@@ -32,7 +32,8 @@ function nodeExpand(
3232
node : Node,
3333
actor?: string,
3434
loadedProperties : LoadedProperties,
35-
createObjectClient : (RdpGrip) => ObjectClient
35+
createObjectClient : CreateObjectClient,
36+
createLongStringClient : CreateLongStringClient
3637
) {
3738
return async ({dispatch} : ThunkArg) => {
3839
dispatch({
@@ -41,7 +42,8 @@ function nodeExpand(
4142
});
4243

4344
if (!loadedProperties.has(node.path)) {
44-
dispatch(nodeLoadProperties(node, actor, loadedProperties, createObjectClient));
45+
dispatch(nodeLoadProperties(node, actor, loadedProperties, createObjectClient,
46+
createLongStringClient));
4547
}
4648
};
4749
}
@@ -67,12 +69,14 @@ function nodeLoadProperties(
6769
item : Node,
6870
actor?: string,
6971
loadedProperties : LoadedProperties,
70-
createObjectClient : (RdpGrip) => ObjectClient
72+
createObjectClient : CreateObjectClient,
73+
createLongStringClient : CreateLongStringClient
7174
) {
7275
return async ({dispatch} : ThunkArg) => {
7376
try {
7477
const properties =
75-
await loadItemProperties(item, createObjectClient, loadedProperties);
78+
await loadItemProperties(item, createObjectClient, createLongStringClient,
79+
loadedProperties);
7680
dispatch(nodePropertiesLoaded(item, actor, properties));
7781
} catch (e) {
7882
console.error(e);

packages/devtools-reps/src/object-inspector/component.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class ObjectInspector extends Component {
178178

179179
const {
180180
createObjectClient,
181+
createLongStringClient,
181182
loadedProperties,
182183
nodeExpand,
183184
nodeCollapse,
@@ -192,7 +193,8 @@ class ObjectInspector extends Component {
192193
return rootValue && rootValue.actor === value.actor;
193194
});
194195
const actor = isRoot || !value ? null : value.actor;
195-
nodeExpand(item, actor, loadedProperties, createObjectClient);
196+
nodeExpand(item, actor, loadedProperties, createObjectClient,
197+
createLongStringClient);
196198
} else {
197199
nodeCollapse(item);
198200
}

packages/devtools-reps/src/object-inspector/types.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,23 @@ export type ObjectClient = {
5050
enumProperties: (options: Object) => Promise<PropertiesIterator>,
5151
enumSymbols: () => Promise<PropertiesIterator>,
5252
getPrototype: () => Promise<{prototype: Object}>,
53-
getString: (object: NodeContents) => Promise<string | NodeContents>,
5453
};
5554

55+
export type LongStringClient = {
56+
substring: (
57+
start: number,
58+
end: number,
59+
response: {
60+
substring?: string,
61+
error?: Error,
62+
message?: string,
63+
}) => void,
64+
}
65+
66+
export type CreateObjectClient = (RdpGrip) => ObjectClient;
67+
68+
export type CreateLongStringClient = (RdpGrip) => LongStringClient;
69+
5670
export type CachedNodes = Map<Path, Array<Node>>;
5771

5872
export type LoadedProperties = Map<Path, GripProperties>;
@@ -74,7 +88,8 @@ export type Props = {
7488
disableWrap: boolean,
7589
dimTopLevelWindow: boolean,
7690
releaseActor: string => void,
77-
createObjectClient: RdpGrip => ObjectClient,
91+
createObjectClient: CreateObjectClient,
92+
createLongStringClient: CreateLongStringClient,
7893
onFocus: ?(Node) => any,
7994
onDoubleClick: ?(
8095
item: Node,

packages/devtools-reps/src/object-inspector/utils/client.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
GripProperties,
88
ObjectClient,
99
PropertiesIterator,
10-
NodeContents,
10+
NodeContents, LongStringClient,
1111
} from "../types";
1212

1313
async function enumIndexedProperties(
@@ -82,14 +82,25 @@ async function getPrototype(
8282
}
8383

8484
async function getFullText(
85-
objectClient: ObjectClient,
85+
longStringClient: LongStringClient,
8686
object: NodeContents,
87-
) : Promise<?string | {}> {
88-
if (typeof objectClient.getString !== "function") {
89-
console.error("objectClient.getString is not a function");
90-
return Promise.resolve({});
91-
}
92-
return objectClient.getString(object);
87+
) : Promise<?Object> {
88+
const { initial, length } = object;
89+
90+
return new Promise((resolve, reject) => {
91+
longStringClient.substring(initial.length, length, response => {
92+
if (response.error) {
93+
console.error("LongStringClient.substring",
94+
response.error + ": " + response.message);
95+
reject({});
96+
return;
97+
}
98+
99+
resolve({
100+
fullText: initial + response.substring
101+
});
102+
});
103+
});
93104
}
94105

95106
function iteratorSlice(

packages/devtools-reps/src/object-inspector/utils/load-properties.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@ const {
2929
} = require("./node");
3030

3131
import type {
32+
CreateLongStringClient,
33+
CreateObjectClient,
3234
GripProperties,
3335
LoadedProperties,
3436
Node,
35-
ObjectClient,
36-
RdpGrip,
3737
} from "../types";
3838

3939
function loadItemProperties(
4040
item : Node,
41-
createObjectClient : (RdpGrip) => ObjectClient,
41+
createObjectClient : CreateObjectClient,
42+
createLongStringClient : CreateLongStringClient,
4243
loadedProperties : LoadedProperties,
4344
) : Promise<GripProperties> {
4445
const gripItem = getClosestGripNode(item);
@@ -72,11 +73,8 @@ function loadItemProperties(
7273
promises.push(enumSymbols(getObjectClient(), start, end));
7374
}
7475

75-
if (shouldLoadFullText(item, loadedProperties)) {
76-
promises.push(
77-
getFullText(getObjectClient(), getValue(item))
78-
.then(fullString => ({fullString}))
79-
);
76+
if (shouldLoadItemFullText(item, loadedProperties)) {
77+
promises.push(getFullText(createLongStringClient(value), value));
8078
}
8179

8280
return Promise.all(promises).then(mergeResponses);
@@ -99,7 +97,7 @@ function mergeResponses(responses: Array<Object>) : Object {
9997
}
10098

10199
if (response.fullText) {
102-
data.fullText = response.response;
100+
data.fullText = response.fullText;
103101
}
104102
}
105103

@@ -189,7 +187,10 @@ function shouldLoadItemSymbols(
189187
&& !nodeIsProxy(item);
190188
}
191189

192-
function shouldLoadFullText(item: Node, loadedProperties: LoadedProperties = new Map()) {
190+
function shouldLoadItemFullText(
191+
item: Node,
192+
loadedProperties: LoadedProperties = new Map()
193+
) {
193194
return !loadedProperties.has(item.path) && nodeIsLongString(item);
194195
}
195196

@@ -201,5 +202,5 @@ module.exports = {
201202
shouldLoadItemNonIndexedProperties,
202203
shouldLoadItemPrototype,
203204
shouldLoadItemSymbols,
204-
shouldLoadFullText
205+
shouldLoadItemFullText
205206
};

0 commit comments

Comments
 (0)