1- // import { DEBUG } from '@glimmer/env' 
2- 
3- // import { consumeTag, createTag, dirtyTag, Tag } from '@glimmer/validator' 
4- // import { consumeTag, createTag, dirtyTag, Tag } from '../tracked-storage' 
5- import  {  formatMs ,  logLater  }  from  './utils' 
61import  { 
72  consumeCollection , 
83  dirtyCollection , 
@@ -28,33 +23,17 @@ class ObjectTreeNode<T extends Record<string, unknown>> implements Node<T> {
2823  id  =  nextId ++ 
2924
3025  constructor ( public  value : T )  { 
31-     // console.log('Object node: ', this.value) 
3226    this . value  =  value 
3327    this . tag . value  =  value 
3428  } 
3529} 
3630
3731const  objectProxyHandler  =  { 
3832  get ( node : Node ,  key : string  |  symbol ) : unknown  { 
39-     // if (DEBUG && key === REDUX_PROXY_LABEL) { 
40-     //   // logLater('Bailing out of getter: ', key) 
41-     //   return true 
42-     // } 
43-     // let res : unknown; 
44- 
45-     const  keyString  =  key . toString ( ) 
46-     // if (keyString === 'constructor') { 
47-     //   console.log('Constructor: ', node) 
48-     // } 
49-     const  start  =  performance . now ( ) 
50- 
5133    function  calculateResult ( )  { 
52-       // try { 
5334      const  {  value }  =  node 
5435
55-       // console.time('Reflect.get: ' + keyString) 
5636      const  childValue  =  Reflect . get ( value ,  key ) 
57-       // console.timeEnd('Reflect.get: ' + keyString) 
5837
5938      if  ( typeof  key  ===  'symbol' )  { 
6039        return  childValue 
@@ -65,55 +44,31 @@ const objectProxyHandler = {
6544      } 
6645
6746      if  ( typeof  childValue  ===  'object'  &&  childValue  !==  null )  { 
68-         // logLater('Getting child node: ', key, childValue) 
6947        let  childNode  =  node . children [ key ] 
7048
7149        if  ( childNode  ===  undefined )  { 
72-           // console.time('Creating child node') 
73- 
74-           // console.log('Creating node: ', key, childValue) 
7550          childNode  =  node . children [ key ]  =  createNode ( childValue ) 
76-           // console.timeEnd('Creating child node') 
7751        } 
7852
7953        if  ( childNode . tag )  { 
80-           // logLater('Consuming tag: ', childNode) 
81-           // console.time('Consuming tag A: ' + keyString) 
82-           // console.log('Consuming tag: ', keyString) 
8354          consumeTag ( childNode . tag ) 
84-           // console.timeEnd('Consuming tag A: ' + keyString) 
8555        } 
8656
8757        return  childNode . proxy 
8858      }  else  { 
8959        let  tag  =  node . tags [ key ] 
90-         if  ( key  ===  'constructor' )  { 
91-           // console.log('Constructor tag: ', tag) 
92-         } 
9360
9461        if  ( tag  ===  undefined )  { 
95-           // console.time('Creating tag: ' + key) 
96-           // console.log('Creating tag: ', key) 
9762          tag  =  node . tags [ key ]  =  createTag ( ) 
98-           // console.timeEnd('Creating tag: ' + key) 
99-           // console.time('Assigning tag value: ' + keyString) 
10063          tag . value  =  childValue 
101-           // console.timeEnd('Assigning tag value: ' + keyString) 
10264        } 
10365
104-         // console.time('Consuming tag B: ' + keyString) 
105-         // console.log('Consuming tag: ', keyString, tag) 
10666        consumeTag ( tag ) 
10767
108-         // console.timeEnd('Consuming tag B: ' + keyString) 
109- 
11068        return  childValue 
11169      } 
11270    } 
11371    const  res  =  calculateResult ( ) 
114- 
115-     const  end  =  performance . now ( ) 
116-     // logLater(`Proxy get trap: ${keyString}: ${formatMs(end - start)}`) 
11772    return  res 
11873  } , 
11974
@@ -126,7 +81,6 @@ const objectProxyHandler = {
12681    node : Node , 
12782    prop : string  |  symbol 
12883  ) : PropertyDescriptor  |  undefined  { 
129-     console . log ( 'getOwnPropertyDescriptor' ,  prop ) 
13084    return  Reflect . getOwnPropertyDescriptor ( node . value ,  prop ) 
13185  } , 
13286
@@ -144,7 +98,6 @@ class ArrayTreeNode<T extends Array<unknown>> implements Node<T> {
14498  id  =  nextId ++ 
14599
146100  constructor ( public  value : T )  { 
147-     // console.log('Array node: ', value) 
148101    this . value  =  value 
149102    this . tag . value  =  value 
150103  } 
@@ -194,14 +147,10 @@ export function updateNode<T extends Array<unknown> | Record<string, unknown>>(
194147  node : Node < T > , 
195148  newValue : T 
196149) : void   { 
197-   // console.log('UpdateNode: ', newValue) 
198150  const  {  value,  tags,  children }  =  node 
199151
200152  node . value  =  newValue 
201153
202-   const  start  =  performance . now ( ) 
203- 
204-   // console.time('updateNode: array check: ' + node.id) 
205154  if  ( 
206155    Array . isArray ( value )  && 
207156    Array . isArray ( newValue )  && 
@@ -214,8 +163,6 @@ export function updateNode<T extends Array<unknown> | Record<string, unknown>>(
214163      let  newKeysSize  =  0 
215164      let  anyKeysAdded  =  false 
216165
217-       // console.log('Key check: ', value, newValue) 
218- 
219166      for  ( const  _key  in  value )  { 
220167        oldKeysSize ++ 
221168      } 
@@ -228,82 +175,19 @@ export function updateNode<T extends Array<unknown> | Record<string, unknown>>(
228175        } 
229176      } 
230177
231-       // let oldKeys = keysMap.get(value) 
232-       // if (!oldKeys) { 
233-       //   oldKeys = new Set<string>() 
234-       //   for (let key in value) { 
235-       //     oldKeys.add(key) 
236-       //   } 
237-       //   keysMap.set(value, oldKeys) 
238-       // } 
239-       // oldKeyIteration = performance.now() 
240-       // let newKeys = keysMap.get(newValue) 
241-       // if (!newKeys) { 
242-       //   newKeys = new Set<string>() 
243-       //   for (let key in newValue) { 
244-       //     newKeys.add(key) 
245-       //   } 
246-       //   keysMap.set(newValue, newKeys) 
247-       // } 
248-       // newKeyIteration = performance.now() 
249-       // // const oldKeys = Object.keys(value) 
250-       // // const newKeys = Object.keys(newValue) 
251-       // const isDifferent = 
252-       //   oldKeys.size !== newKeys.size || anyKeysDifferent(oldKeys, newKeys) 
253- 
254178      const  isDifferent  =  anyKeysAdded  ||  oldKeysSize  !==  newKeysSize 
255179
256-       if  ( 
257-         isDifferent 
258-         // [...oldKeys].some((k) => !newKeys!.has(k)) 
259-       )  { 
260-         // console.log('Dirtying collection: ', node) 
180+       if  ( isDifferent )  { 
261181        dirtyCollection ( node ) 
262182      } 
263183    } 
264-     // console.time('Checking object keys') 
265-     // let oldKeys = keysMap.get(value) 
266-     // if (!oldKeys) { 
267-     //   oldKeys = new Set<string>() 
268-     //   for (const key in value) { 
269-     //     oldKeys.add(key) 
270-     //   } 
271-     //   keysMap.set(value, oldKeys) 
272-     // } 
273-     // let newKeys = keysMap.get(value) 
274-     // if (!newKeys) { 
275-     //   newKeys = new Set<string>() 
276-     //   for (const key in newValue) { 
277-     //     newKeys.add(key) 
278-     //   } 
279-     //   keysMap.set(newValue, newKeys) 
280-     // } 
281-     // // const oldKeys = Object.keys(value) 
282-     // // const newKeys = Object.keys(newValue) 
283- 
284-     // if ( 
285-     //   oldKeys.size !== newKeys.size || 
286-     //   [...oldKeys].some(k => !newKeys!.has(k)) 
287-     // ) { 
288-     //   dirtyCollection(node) 
289-     // } 
290-     // console.timeEnd('Checking object keys') 
291184  } 
292185
293-   const  arrayDone  =  performance . now ( ) 
294- 
295-   // console.timeEnd('updateNode: array check: ' + node.id) 
296- 
297-   // console.time('updateNode: tags check: ' + node.id) 
298- 
299-   // console.log('Tags: ', tags) 
300186  for  ( const  key  in  tags )  { 
301-     // logLater('Tag key: ', key) 
302187    const  childValue  =  ( value  as  Record < string ,  unknown > ) [ key ] 
303188    const  newChildValue  =  ( newValue  as  Record < string ,  unknown > ) [ key ] 
304189
305190    if  ( childValue  !==  newChildValue )  { 
306-       // console.log('Dirtying tag: ', { key, childValue, newChildValue }) 
307191      dirtyCollection ( node ) 
308192      dirtyTag ( tags [ key ] ,  newChildValue ) 
309193    } 
@@ -313,51 +197,21 @@ export function updateNode<T extends Array<unknown> | Record<string, unknown>>(
313197    } 
314198  } 
315199
316-   const  tagsDone  =  performance . now ( ) 
317- 
318-   // console.timeEnd('updateNode: tags check: ' + node.id) 
319- 
320-   // console.time('updateNode: keys check: ' + node.id) 
321- 
322200  for  ( const  key  in  children )  { 
323-     // logLater('Child key: ', key) 
324201    const  childNode  =  children [ key ] 
325202    const  newChildValue  =  ( newValue  as  Record < string ,  unknown > ) [ key ] 
326203
327204    const  childValue  =  childNode . value 
328205
329206    if  ( childValue  ===  newChildValue )  { 
330-       // logLater('Skipping child node: ', key, childValue, newChildValue) 
331207      continue 
332-     }  else  if  ( 
333-       typeof  newChildValue  ===  'object'  && 
334-       newChildValue  !==  null  // && 
335-       // Object.getPrototypeOf(newChildValue) === Object.getPrototypeOf(childValue) 
336-     )  { 
337-       // logLater('Updating child node: ', key, childValue, newChildValue) 
338-       // console.time('Nested updateNode: ' + key) 
208+     }  else  if  ( typeof  newChildValue  ===  'object'  &&  newChildValue  !==  null )  { 
339209      updateNode ( childNode ,  newChildValue  as  Record < string ,  unknown > ) 
340-       // console.timeEnd('Nested updateNode: ' + key) 
341210    }  else  { 
342211      deleteNode ( childNode ) 
343212      delete  children [ key ] 
344213    } 
345214  } 
346- 
347-   const  keysDone  =  performance . now ( ) 
348- 
349-   // logLater( 
350-   //   'updateNode: ', 
351-   //   { 
352-   //     total: formatMs(keysDone - start), 
353-   //     array: formatMs(arrayDone - start), 
354-   //     tags: formatMs(tagsDone - arrayDone), 
355-   //     keys: formatMs(keysDone - tagsDone) 
356-   //   }, 
357-   //   node.value 
358-   // ) 
359- 
360-   // console.timeEnd('updateNode: keys check: ' + node.id) 
361215} 
362216
363217function  deleteNode ( node : Node ) : void   { 
@@ -371,6 +225,4 @@ function deleteNode(node: Node): void {
371225  for  ( const  key  in  node . children )  { 
372226    deleteNode ( node . children [ key ] ) 
373227  } 
374-   // Object.values(node.tags).map(dirtyTag) 
375-   // Object.values(node.children).map(deleteNode) 
376228} 
0 commit comments