From 3aee101c73d0a3f72db35a5c60cf2c5130307cae Mon Sep 17 00:00:00 2001 From: nikoloza Date: Thu, 13 Jul 2023 08:35:31 +0400 Subject: [PATCH] inherited state, create if does not exist --- packages/state/inherit.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/state/inherit.js b/packages/state/inherit.js index e916cd25..d371015d 100644 --- a/packages/state/inherit.js +++ b/packages/state/inherit.js @@ -20,11 +20,13 @@ export const getChildStateInKey = (stateKey, parentState, options = {}) => { for (let i = 0; i < arrLength; i++) { const childKey = arr[i] const grandChildKey = arr[i + 1] - const childInParent = parentState[childKey] - if (childInParent && childInParent[grandChildKey]) { - stateKey = grandChildKey - parentState = childInParent - } else return + + let childInParent = parentState[childKey] + if (!childInParent) childInParent = parentState[childKey] = {} + if (!childInParent[grandChildKey]) childInParent[grandChildKey] = {} + + stateKey = grandChildKey + parentState = childInParent } if (options.returnParent) return parentState return parentState[stateKey]