Closed Bug 896103 Opened 11 years ago Closed 11 years ago

NodeListActor's items() response has unnecessary nesting

Categories

(DevTools :: Inspector, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 25

People

(Reporter: harth, Assigned: dcamp)

Details

Attachments

(1 file)

Response from an items() request:

{"nodes":{"nodes":[{"actor":"conn3.domnode16","parent":"conn3.domnode19","nodeType":1,"nodeName":"DIV","numChildren":0,"attrs":[{"name":"class","value":"item"},{"name":"id","value":"test1"}]},{"actor":"conn3.domnode17","parent":"conn3.domnode19","nodeType":1,"nodeName":"DIV","numChildren":5,"attrs":[{"name":"class","value":"item"},{"name":"id","value":"test2"}]},{"actor":"conn3.domnode18","parent":"conn3.domnode19","nodeType":1,"nodeName":"DIV","numChildren":0,"attrs":[{"name":"class","value":"item"},{"name":"id","value":"test3"}]}],"newNodes":[{"actor":"conn3.domnode19","parent":"conn3.domnode20","nodeType":1,"nodeName":"SECTION","numChildren":7,"attrs":[{"name":"id","value":"test-section"}]},{"actor":"conn3.domnode20","parent":"conn3.domnode21","nodeType":1,"nodeName":"MAIN","numChildren":3,"attrs":[]},{"actor":"conn3.domnode21","parent":"conn3.domnode22","nodeType":1,"nodeName":"BODY","numChildren":3,"attrs":[]},{"actor":"conn3.domnode22","parent":"conn3.domnode13","nodeType":1,"nodeName":"HTML","numChildren":3,"attrs":[],"isDocumentElement":true}]},"from":"conn3.domnodelist15"}

Notice the nodes.nodes and nodes.newNodes. Seems like it could just be nodes and newNodes.

I wish we had a single field for the return value across all the actors, like "result"

What is newNodes for?
Yeah, we should get rid of the useless extra nesting.

`nodes` is an array of nodes that answer the question being asked (like the querySelector nodes).

To make things sane for the client, we make sure that when you have a node reference on the client side, you also have a reference to all of its parents (so that parentNode can be sync).  newNodes fills in any parents that the client doesn't know about yet.
(In reply to Dave Camp (:dcamp) from comment #1)
> To make things sane for the client, we make sure that when you have a node
> reference on the client side, you also have a reference to all of its
> parents (so that parentNode can be sync).  newNodes fills in any parents
> that the client doesn't know about yet.

Ah, maybe newNodes should be named something else?

I'm curious about this use case. Why you'd need it to be sync over other things like getting children that are async?
(In reply to Heather Arthur [:harth] from comment #2)
> Ah, maybe newNodes should be named something else?

Yeah, any suggestions?

> I'm curious about this use case. Why you'd need it to be sync over other
> things like getting children that are async?

It's mostly related to the algorithm we use to release memory for disconnected nodes - when a node is disconnected from the dom tree we want to be able to free the client objects for all the children nodes.

So to be able to answer "all the children of a given node that we have seen on the client side", we guarantee that every time we've seen a node, we connect it up through its parents.

Clients don't need to implement the collection algorithm.  In that case they're free to ignore the newNodes (maybe newParents? unseenParents?).

I'll submit a patch that puts this documentation in the file somewhere.
Attached patch v1`Splinter Review
Attachment #778866 - Flags: review?(fayearthur)
Comment on attachment 778866 [details] [diff] [review]
v1`

Review of attachment 778866 [details] [diff] [review]:
-----------------------------------------------------------------

Ah, I see.

Looks good, thanks!
Attachment #778866 - Flags: review?(fayearthur) → review+
https://hg.mozilla.org/integration/fx-team/rev/05ff12c00114
Assignee: nobody → dcamp
Whiteboard: [fixed-in-fx-team]
https://hg.mozilla.org/mozilla-central/rev/05ff12c00114
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Whiteboard: [fixed-in-fx-team]
Target Milestone: --- → Firefox 25
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: