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

Commit

Permalink
Re-create loadItemProperties function which is used by the debugger.
Browse files Browse the repository at this point in the history
The function was deleted in https://github.com/devtools-html/devtools-core/commit/7c538787e1f19c07e868192268097f6c8845feb2\#diff-1d5a77fb4120fb410c4af9fa9a4eb936
because it wasn't used in devtools-reps code.
But it was exported and the debugger does use it for
the Preview popup.
So we re-create it and make sure the similar action use
it as well so the ObjectInspector and debugger code path
don't diverge.
  • Loading branch information
nchevobbe committed Mar 19, 2018
1 parent 0a2b03f commit 89fba99
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 81 deletions.
68 changes: 11 additions & 57 deletions packages/devtools-reps/src/object-inspector/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,25 @@
// @flow

import type {
GripProperties,
LoadedProperties,
Node,
ObjectClient,
RdpGrip,
ReduxAction,
} from "./types";

const {
loadItemProperties,
} = require("./utils/load-properties");

type Dispatch = ReduxAction => void;

type ThunkArg = {
getState: () => {},
dispatch: Dispatch,
}

const {
getClosestGripNode,
getValue,
} = require("./utils/node");

const {
shouldLoadItemEntries,
shouldLoadItemIndexedProperties,
shouldLoadItemNonIndexedProperties,
shouldLoadItemPrototype,
shouldLoadItemSymbols,
} = require("./utils/load-properties");

const {
enumEntries,
enumIndexedProperties,
enumNonIndexedProperties,
getPrototype,
enumSymbols,
} = require("./utils/client");

/**
* This action is responsible for expanding a given node,
* which also means that it will call the action responsible to fetch properties.
Expand Down Expand Up @@ -84,40 +68,10 @@ function nodeLoadProperties(
) {
return async ({dispatch} : ThunkArg) => {
try {
const gripItem = getClosestGripNode(item);
const value = getValue(gripItem);

const [start, end] = item.meta
? [item.meta.startIndex, item.meta.endIndex]
: [];

let promises = [];
let objectClient;
const getObjectClient = () => objectClient || createObjectClient(value);

if (shouldLoadItemIndexedProperties(item, loadedProperties)) {
promises.push(enumIndexedProperties(getObjectClient(), start, end));
}

if (shouldLoadItemNonIndexedProperties(item, loadedProperties)) {
promises.push(enumNonIndexedProperties(getObjectClient(), start, end));
}

if (shouldLoadItemEntries(item, loadedProperties)) {
promises.push(enumEntries(getObjectClient(), start, end));
}

if (shouldLoadItemPrototype(item, loadedProperties)) {
promises.push(getPrototype(getObjectClient()));
}

if (shouldLoadItemSymbols(item, loadedProperties)) {
promises.push(enumSymbols(getObjectClient(), start, end));
}

if (promises.length > 0) {
const responses = await Promise.all(promises);
dispatch(nodePropertiesLoaded(item, actor, responses));
const properties =
await loadItemProperties(item, createObjectClient, loadedProperties);
if (Object.keys(properties).length > 0) {
dispatch(nodePropertiesLoaded(item, actor, properties));
}
} catch (e) {
console.error(e);
Expand All @@ -128,11 +82,11 @@ function nodeLoadProperties(
function nodePropertiesLoaded(
node : Node,
actor?: string,
responses : Array<LoadedProperties>
properties: GripProperties
) {
return {
type: "NODE_PROPERTIES_LOADED",
data: {node, actor, responses}
data: {node, actor, properties}
};
}

Expand Down
25 changes: 1 addition & 24 deletions packages/devtools-reps/src/object-inspector/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ function reducer(
}

if (type === "NODE_PROPERTIES_LOADED") {
// Let's loop through the responses to build a single object.
const properties = mergeResponses(data.responses);

return cloneState({
actors: data.actor ? (new Set(state.actors || [])).add(data.actor) : state.actors,
loadedProperties: (new Map(state.loadedProperties))
.set(data.node.path, properties),
.set(data.node.path, action.data.properties),
});
}

Expand All @@ -51,24 +48,4 @@ function reducer(
return state;
}

function mergeResponses(responses: Array<Object>) : Object {
const data = {};

for (const response of responses) {
if (response.hasOwnProperty("ownProperties")) {
data.ownProperties = {...data.ownProperties, ...response.ownProperties};
}

if (response.ownSymbols && response.ownSymbols.length > 0) {
data.ownSymbols = response.ownSymbols;
}

if (response.prototype) {
data.prototype = response.prototype;
}
}

return data;
}

module.exports = reducer;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const {
enumEntries,
enumIndexedProperties,
enumNonIndexedProperties,
getPrototype,
enumSymbols,
} = require("./client");

const {
getClosestGripNode,
getClosestNonBucketNode,
Expand All @@ -19,10 +27,72 @@ const {
} = require("./node");

import type {
GripProperties,
LoadedProperties,
Node,
ObjectClient,
RdpGrip,
} from "../types";

function loadItemProperties(
item : Node,
createObjectClient : (RdpGrip) => ObjectClient,
loadedProperties : LoadedProperties,
) : Promise<GripProperties> {
const gripItem = getClosestGripNode(item);
const value = getValue(gripItem);

const [start, end] = item.meta
? [item.meta.startIndex, item.meta.endIndex]
: [];

let promises = [];
let objectClient;
const getObjectClient = () => objectClient || createObjectClient(value);

if (shouldLoadItemIndexedProperties(item, loadedProperties)) {
promises.push(enumIndexedProperties(getObjectClient(), start, end));
}

if (shouldLoadItemNonIndexedProperties(item, loadedProperties)) {
promises.push(enumNonIndexedProperties(getObjectClient(), start, end));
}

if (shouldLoadItemEntries(item, loadedProperties)) {
promises.push(enumEntries(getObjectClient(), start, end));
}

if (shouldLoadItemPrototype(item, loadedProperties)) {
promises.push(getPrototype(getObjectClient()));
}

if (shouldLoadItemSymbols(item, loadedProperties)) {
promises.push(enumSymbols(getObjectClient(), start, end));
}

return Promise.all(promises).then(mergeResponses);
}

function mergeResponses(responses: Array<Object>) : Object {
const data = {};

for (const response of responses) {
if (response.hasOwnProperty("ownProperties")) {
data.ownProperties = {...data.ownProperties, ...response.ownProperties};
}

if (response.ownSymbols && response.ownSymbols.length > 0) {
data.ownSymbols = response.ownSymbols;
}

if (response.prototype) {
data.prototype = response.prototype;
}
}

return data;
}

function shouldLoadItemIndexedProperties(
item: Node,
loadedProperties: LoadedProperties = new Map()
Expand Down Expand Up @@ -105,6 +175,8 @@ function shouldLoadItemSymbols(
}

module.exports = {
loadItemProperties,
mergeResponses,
shouldLoadItemEntries,
shouldLoadItemIndexedProperties,
shouldLoadItemNonIndexedProperties,
Expand Down

0 comments on commit 89fba99

Please sign in to comment.