@@ -10,7 +10,7 @@ import {
1010 isComponentState ,
1111 isContainerState ,
1212} from "@/lib/types/state/component" ;
13- import { formatObjPath , getValue , normalizeObjPath } from "@/lib/utils/objPath" ;
13+ import { formatObjPath , getValue , type ObjPathLike } from "@/lib/utils/objPath" ;
1414import { isObject } from "@/lib/utils/isObject" ;
1515import type { HostStore } from "@/lib/types/state/options" ;
1616
@@ -32,12 +32,17 @@ export function getInputValue(
3232 hostStore ?: HostStore ,
3333) : unknown {
3434 let inputValue : unknown = undefined ;
35+ const { id, property } = input ;
3536 if ( isComponentChannel ( input ) && contributionState . component ) {
36- inputValue = getInputValueFromComponent ( input , contributionState . component ) ;
37+ inputValue = getInputValueFromComponent (
38+ contributionState . component ,
39+ id ,
40+ property ,
41+ ) ;
3742 } else if ( isContainerChannel ( input ) && contributionState . container ) {
38- inputValue = getInputValueFromState ( input , contributionState . container ) ;
43+ inputValue = getInputValueFromState ( contributionState . container , property ) ;
3944 } else if ( isHostChannel ( input ) && hostStore ) {
40- inputValue = getInputValueFromHostStore ( input , hostStore ) ;
45+ inputValue = getInputValueFromHostStore ( hostStore , property ) ;
4146 } else {
4247 console . warn ( `input with unknown data source:` , input ) ;
4348 }
@@ -51,16 +56,17 @@ export function getInputValue(
5156
5257// we export for testing only
5358export function getInputValueFromComponent (
54- input : Input ,
5559 componentState : ComponentState ,
60+ id : string ,
61+ property : ObjPathLike ,
5662) : unknown {
57- if ( componentState . id === input . id ) {
58- return getValue ( componentState , input . property ) ;
63+ if ( componentState . id === id ) {
64+ return getValue ( componentState , property ) ;
5965 } else if ( isContainerState ( componentState ) ) {
6066 for ( let i = 0 ; i < componentState . children . length ; i ++ ) {
6167 const item = componentState . children [ i ] ;
6268 if ( isComponentState ( item ) ) {
63- const itemValue = getInputValueFromComponent ( input , item ) ;
69+ const itemValue = getInputValueFromComponent ( item , id , property ) ;
6470 if ( itemValue !== noValue ) {
6571 return itemValue ;
6672 }
@@ -72,24 +78,16 @@ export function getInputValueFromComponent(
7278
7379// we export for testing only
7480export function getInputValueFromState (
75- input : Input ,
7681 state : object | undefined ,
82+ property : ObjPathLike ,
7783) : unknown {
78- let inputValue : unknown = state ;
79- if ( input . id && isObject ( inputValue ) ) {
80- inputValue = inputValue [ input . id ] ;
81- }
82- if ( isObject ( inputValue ) ) {
83- const state = inputValue ;
84- const property = normalizeObjPath ( input . property ) ;
85- inputValue = getValue ( state , property ) ;
86- }
87- return inputValue ;
84+ return isObject ( state ) ? getValue ( state , property ) : undefined ;
8885}
8986
87+ // we export for testing only
9088export function getInputValueFromHostStore (
91- input : Input ,
9289 hostStore : HostStore ,
90+ property : ObjPathLike ,
9391) : unknown {
94- return hostStore . get ( formatObjPath ( input . property ) ) ;
92+ return hostStore . get ( formatObjPath ( property ) ) ;
9593}
0 commit comments