22 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
5- const {
6- enumEntries,
7- enumIndexedProperties,
8- enumNonIndexedProperties,
9- getPrototype,
10- enumSymbols,
11- } = require ( "./client" ) ;
12-
135const {
146 getClosestGripNode,
157 getClosestNonBucketNode,
@@ -27,77 +19,10 @@ const {
2719} = require ( "./node" ) ;
2820
2921import type {
30- GripProperties ,
3122 LoadedProperties ,
3223 Node ,
33- NodeContents ,
34- ObjectClient ,
35- RdpGrip ,
3624} from "../types" ;
3725
38- function loadItemProperties (
39- item : Node ,
40- createObjectClient : ( RdpGrip | NodeContents ) = > ObjectClient ,
41- loadedProperties : LoadedProperties
42- ) : Promise < GripProperties > | null {
43- const [ start , end ] = item . meta
44- ? [ item . meta . startIndex , item . meta . endIndex ]
45- : [ ] ;
46-
47- let objectClient ;
48- const getObjectClient = ( ) => {
49- if ( objectClient ) {
50- return objectClient ;
51- }
52-
53- const gripItem = getClosestGripNode ( item ) ;
54- const value = getValue ( gripItem ) ;
55- return createObjectClient ( value ) ;
56- } ;
57-
58- let loadingPromises = [ ] ;
59- if ( shouldLoadItemIndexedProperties ( item , loadedProperties ) ) {
60- loadingPromises . push ( enumIndexedProperties ( getObjectClient ( ) , start , end ) ) ;
61- }
62-
63- if ( shouldLoadItemNonIndexedProperties ( item , loadedProperties ) ) {
64- loadingPromises . push ( enumNonIndexedProperties ( getObjectClient ( ) , start , end ) ) ;
65- }
66-
67- if ( shouldLoadItemEntries ( item , loadedProperties ) ) {
68- loadingPromises . push ( enumEntries ( getObjectClient ( ) , start , end ) ) ;
69- }
70-
71- if ( shouldLoadItemPrototype ( item , loadedProperties ) ) {
72- loadingPromises . push ( getPrototype ( getObjectClient ( ) ) ) ;
73- }
74-
75- if ( shouldLoadItemSymbols ( item , loadedProperties ) ) {
76- loadingPromises . push ( enumSymbols ( getObjectClient ( ) , start , end ) ) ;
77- }
78-
79- if ( loadingPromises . length === 0 ) {
80- return null ;
81- }
82-
83- return Promise . all ( loadingPromises )
84- . then ( responses => responses . reduce ( ( accumulator , res ) => {
85- // Let's loop through the responses to build a single response object.
86- Object . entries ( res ) . forEach ( ( [ k , v ] ) => {
87- if ( accumulator . hasOwnProperty ( k ) ) {
88- if ( Array . isArray ( accumulator [ k ] ) ) {
89- accumulator [ k ] . push ( ...v ) ;
90- } else if ( typeof accumulator [ k ] === "object" ) {
91- accumulator [ k ] = Object . assign ( { } , accumulator [ k ] , v ) ;
92- }
93- } else {
94- accumulator [ k ] = v ;
95- }
96- } ) ;
97- return accumulator ;
98- } , { } ) ) ;
99- }
100-
10126function shouldLoadItemIndexedProperties (
10227 item : Node ,
10328 loadedProperties : LoadedProperties = new Map ( )
@@ -180,7 +105,6 @@ function shouldLoadItemSymbols(
180105}
181106
182107module . exports = {
183- loadItemProperties,
184108 shouldLoadItemEntries,
185109 shouldLoadItemIndexedProperties,
186110 shouldLoadItemNonIndexedProperties,
0 commit comments