@json-layout/core 0.26.0 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/state/index.js +4 -0
- package/src/state/state-node.js +19 -10
- package/src/state/types.ts +2 -2
package/package.json
CHANGED
package/src/state/index.js
CHANGED
|
@@ -295,6 +295,10 @@ export class StatefulLayout {
|
|
|
295
295
|
files: [],
|
|
296
296
|
nodes: []
|
|
297
297
|
}
|
|
298
|
+
|
|
299
|
+
// @ts-ignore
|
|
300
|
+
if (this._options._debugCache) createStateTreeContext._debugCache = this._lastCreateStateTreeContext?._debugCache ?? {}
|
|
301
|
+
|
|
298
302
|
this._stateTree = createStateTree(
|
|
299
303
|
createStateTreeContext,
|
|
300
304
|
this._options,
|
package/src/state/state-node.js
CHANGED
|
@@ -270,11 +270,20 @@ export function createStateNode (
|
|
|
270
270
|
|
|
271
271
|
// NOTE we have to exclude nodes with errors from the cache, because context.errors is unpurely modified
|
|
272
272
|
// TODO: implement a cleaner way to filter context.errors while being able to reuse nodes with errors
|
|
273
|
-
if (skeleton.pure &&
|
|
274
|
-
|
|
275
|
-
|
|
273
|
+
if (skeleton.pure && !reusedNode?.error && !reusedNode?.childError) {
|
|
274
|
+
const validatedCacheKey = validationState.validatedForm || validationState.validatedChildren.includes(fullKey)
|
|
275
|
+
cacheKey = [parentOptions, compiledLayout, fullKey, skeleton, childDefinition, parentDisplay.width, validatedCacheKey, context.activatedItems, context.initial, data]
|
|
276
|
+
if (reusedNode && context.cacheKeys[fullKey] && shallowEqualArray(context.cacheKeys[fullKey], cacheKey)) {
|
|
277
|
+
// @ts-ignore
|
|
278
|
+
if (context._debugCache) context._debugCache[fullKey] = (context._debugCache[fullKey] ?? []).concat(['hit'])
|
|
276
279
|
return reusedNode
|
|
280
|
+
} else {
|
|
281
|
+
// @ts-ignore
|
|
282
|
+
if (context._debugCache) context._debugCache[fullKey] = (context._debugCache[fullKey] ?? []).concat(['miss'])
|
|
277
283
|
}
|
|
284
|
+
} else {
|
|
285
|
+
// @ts-ignore
|
|
286
|
+
if (context._debugCache) context._debugCache[fullKey] = (context._debugCache[fullKey] ?? []).concat(['skip'])
|
|
278
287
|
}
|
|
279
288
|
|
|
280
289
|
const normalizedLayout = childDefinition && childIsCompObject(childDefinition)
|
|
@@ -428,19 +437,19 @@ export function createStateNode (
|
|
|
428
437
|
})
|
|
429
438
|
}
|
|
430
439
|
}
|
|
431
|
-
const validated = validationState.validatedForm ||
|
|
432
|
-
validationState.validatedChildren.includes(fullKey) ||
|
|
433
|
-
(validationState.initialized === false && options.initialValidation === 'always') ||
|
|
434
|
-
(validationState.initialized === false && options.initialValidation === 'withData' && !isDataEmpty(data))
|
|
435
440
|
|
|
436
441
|
let nodeData = data
|
|
437
|
-
|
|
438
442
|
if (nodeData === null && !layout.nullable) nodeData = undefined
|
|
439
443
|
|
|
444
|
+
const validated = validationState.validatedForm ||
|
|
445
|
+
validationState.validatedChildren.includes(fullKey) ||
|
|
446
|
+
(validationState.initialized === false && options.initialValidation === 'always') ||
|
|
447
|
+
(validationState.initialized === false && options.initialValidation === 'withData' && !isDataEmpty(nodeData))
|
|
448
|
+
|
|
440
449
|
/** @type {unknown} */
|
|
441
|
-
if (typeof nodeData === 'object' && !(nodeData instanceof File)) {
|
|
450
|
+
if ((typeof nodeData === 'object' || (nodeData === undefined && children?.length)) && !(nodeData instanceof File)) {
|
|
442
451
|
nodeData = produceStateNodeData(
|
|
443
|
-
/** @type {Record<string, unknown>} */(nodeData ?? {}),
|
|
452
|
+
/** @type {Record<string, unknown>} */(nodeData ?? (typeof children?.[0]?.key === 'number' ? [] : {})),
|
|
444
453
|
dataPath,
|
|
445
454
|
children,
|
|
446
455
|
context.additionalPropertiesErrors,
|
package/src/state/types.ts
CHANGED
|
@@ -76,7 +76,7 @@ export interface FileRef {
|
|
|
76
76
|
dataPath: string
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
// [parentOptions, compiledLayout, fullKey, skeleton, childDefinition, parentWidth,
|
|
79
|
+
// [parentOptions, compiledLayout, fullKey, skeleton, childDefinition, parentWidth, validated, activatedItems, initial, data]
|
|
80
80
|
export type StateNodeCacheKey = [
|
|
81
81
|
StateNodeOptions,
|
|
82
82
|
CompiledLayout,
|
|
@@ -84,7 +84,7 @@ export type StateNodeCacheKey = [
|
|
|
84
84
|
SkeletonNode,
|
|
85
85
|
Child | null,
|
|
86
86
|
number,
|
|
87
|
-
|
|
87
|
+
boolean,
|
|
88
88
|
Record<string, number>,
|
|
89
89
|
boolean,
|
|
90
90
|
unknown
|