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'
6
1
import {
7
2
consumeCollection ,
8
3
dirtyCollection ,
@@ -28,33 +23,17 @@ class ObjectTreeNode<T extends Record<string, unknown>> implements Node<T> {
28
23
id = nextId ++
29
24
30
25
constructor ( public value : T ) {
31
- // console.log('Object node: ', this.value)
32
26
this . value = value
33
27
this . tag . value = value
34
28
}
35
29
}
36
30
37
31
const objectProxyHandler = {
38
32
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
-
51
33
function calculateResult ( ) {
52
- // try {
53
34
const { value } = node
54
35
55
- // console.time('Reflect.get: ' + keyString)
56
36
const childValue = Reflect . get ( value , key )
57
- // console.timeEnd('Reflect.get: ' + keyString)
58
37
59
38
if ( typeof key === 'symbol' ) {
60
39
return childValue
@@ -65,55 +44,31 @@ const objectProxyHandler = {
65
44
}
66
45
67
46
if ( typeof childValue === 'object' && childValue !== null ) {
68
- // logLater('Getting child node: ', key, childValue)
69
47
let childNode = node . children [ key ]
70
48
71
49
if ( childNode === undefined ) {
72
- // console.time('Creating child node')
73
-
74
- // console.log('Creating node: ', key, childValue)
75
50
childNode = node . children [ key ] = createNode ( childValue )
76
- // console.timeEnd('Creating child node')
77
51
}
78
52
79
53
if ( childNode . tag ) {
80
- // logLater('Consuming tag: ', childNode)
81
- // console.time('Consuming tag A: ' + keyString)
82
- // console.log('Consuming tag: ', keyString)
83
54
consumeTag ( childNode . tag )
84
- // console.timeEnd('Consuming tag A: ' + keyString)
85
55
}
86
56
87
57
return childNode . proxy
88
58
} else {
89
59
let tag = node . tags [ key ]
90
- if ( key === 'constructor' ) {
91
- // console.log('Constructor tag: ', tag)
92
- }
93
60
94
61
if ( tag === undefined ) {
95
- // console.time('Creating tag: ' + key)
96
- // console.log('Creating tag: ', key)
97
62
tag = node . tags [ key ] = createTag ( )
98
- // console.timeEnd('Creating tag: ' + key)
99
- // console.time('Assigning tag value: ' + keyString)
100
63
tag . value = childValue
101
- // console.timeEnd('Assigning tag value: ' + keyString)
102
64
}
103
65
104
- // console.time('Consuming tag B: ' + keyString)
105
- // console.log('Consuming tag: ', keyString, tag)
106
66
consumeTag ( tag )
107
67
108
- // console.timeEnd('Consuming tag B: ' + keyString)
109
-
110
68
return childValue
111
69
}
112
70
}
113
71
const res = calculateResult ( )
114
-
115
- const end = performance . now ( )
116
- // logLater(`Proxy get trap: ${keyString}: ${formatMs(end - start)}`)
117
72
return res
118
73
} ,
119
74
@@ -126,7 +81,6 @@ const objectProxyHandler = {
126
81
node : Node ,
127
82
prop : string | symbol
128
83
) : PropertyDescriptor | undefined {
129
- console . log ( 'getOwnPropertyDescriptor' , prop )
130
84
return Reflect . getOwnPropertyDescriptor ( node . value , prop )
131
85
} ,
132
86
@@ -144,7 +98,6 @@ class ArrayTreeNode<T extends Array<unknown>> implements Node<T> {
144
98
id = nextId ++
145
99
146
100
constructor ( public value : T ) {
147
- // console.log('Array node: ', value)
148
101
this . value = value
149
102
this . tag . value = value
150
103
}
@@ -194,14 +147,10 @@ export function updateNode<T extends Array<unknown> | Record<string, unknown>>(
194
147
node : Node < T > ,
195
148
newValue : T
196
149
) : void {
197
- // console.log('UpdateNode: ', newValue)
198
150
const { value, tags, children } = node
199
151
200
152
node . value = newValue
201
153
202
- const start = performance . now ( )
203
-
204
- // console.time('updateNode: array check: ' + node.id)
205
154
if (
206
155
Array . isArray ( value ) &&
207
156
Array . isArray ( newValue ) &&
@@ -214,8 +163,6 @@ export function updateNode<T extends Array<unknown> | Record<string, unknown>>(
214
163
let newKeysSize = 0
215
164
let anyKeysAdded = false
216
165
217
- // console.log('Key check: ', value, newValue)
218
-
219
166
for ( const _key in value ) {
220
167
oldKeysSize ++
221
168
}
@@ -228,82 +175,19 @@ export function updateNode<T extends Array<unknown> | Record<string, unknown>>(
228
175
}
229
176
}
230
177
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
-
254
178
const isDifferent = anyKeysAdded || oldKeysSize !== newKeysSize
255
179
256
- if (
257
- isDifferent
258
- // [...oldKeys].some((k) => !newKeys!.has(k))
259
- ) {
260
- // console.log('Dirtying collection: ', node)
180
+ if ( isDifferent ) {
261
181
dirtyCollection ( node )
262
182
}
263
183
}
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')
291
184
}
292
185
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)
300
186
for ( const key in tags ) {
301
- // logLater('Tag key: ', key)
302
187
const childValue = ( value as Record < string , unknown > ) [ key ]
303
188
const newChildValue = ( newValue as Record < string , unknown > ) [ key ]
304
189
305
190
if ( childValue !== newChildValue ) {
306
- // console.log('Dirtying tag: ', { key, childValue, newChildValue })
307
191
dirtyCollection ( node )
308
192
dirtyTag ( tags [ key ] , newChildValue )
309
193
}
@@ -313,51 +197,21 @@ export function updateNode<T extends Array<unknown> | Record<string, unknown>>(
313
197
}
314
198
}
315
199
316
- const tagsDone = performance . now ( )
317
-
318
- // console.timeEnd('updateNode: tags check: ' + node.id)
319
-
320
- // console.time('updateNode: keys check: ' + node.id)
321
-
322
200
for ( const key in children ) {
323
- // logLater('Child key: ', key)
324
201
const childNode = children [ key ]
325
202
const newChildValue = ( newValue as Record < string , unknown > ) [ key ]
326
203
327
204
const childValue = childNode . value
328
205
329
206
if ( childValue === newChildValue ) {
330
- // logLater('Skipping child node: ', key, childValue, newChildValue)
331
207
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 ) {
339
209
updateNode ( childNode , newChildValue as Record < string , unknown > )
340
- // console.timeEnd('Nested updateNode: ' + key)
341
210
} else {
342
211
deleteNode ( childNode )
343
212
delete children [ key ]
344
213
}
345
214
}
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)
361
215
}
362
216
363
217
function deleteNode ( node : Node ) : void {
@@ -371,6 +225,4 @@ function deleteNode(node: Node): void {
371
225
for ( const key in node . children ) {
372
226
deleteNode ( node . children [ key ] )
373
227
}
374
- // Object.values(node.tags).map(dirtyTag)
375
- // Object.values(node.children).map(deleteNode)
376
228
}
0 commit comments