@@ -61,12 +61,28 @@ export default function handleComponentPropertyChange(
6161 }
6262 }
6363 } ) ;
64+ const originalChangeRequest : ChangeRequest = {
65+ contribPoint,
66+ contribIndex,
67+ changes : [
68+ {
69+ kind : "Component" ,
70+ id : componentId ,
71+ property : componentPropertyName ,
72+ value : componentPropertyValue ,
73+ } ,
74+ ] ,
75+ } ;
6476 console . debug ( "callRequests" , callRequests ) ;
65- if ( callRequests . length ) {
77+ if ( callRequests . length == 0 ) {
78+ applyChangeRequests ( [ originalChangeRequest ] ) ;
79+ } else {
6680 fetchApiResult ( fetchChangeRequests , callRequests ) . then (
6781 ( changeRequestsResult ) => {
6882 if ( changeRequestsResult . data ) {
69- applyChangeRequests ( changeRequestsResult . data ) ;
83+ applyChangeRequests (
84+ [ originalChangeRequest ] . concat ( changeRequestsResult . data ) ,
85+ ) ;
7086 } else {
7187 console . error (
7288 "callback failed:" ,
@@ -81,23 +97,28 @@ export default function handleComponentPropertyChange(
8197}
8298
8399function applyChangeRequests ( changeRequests : ChangeRequest [ ] ) {
84- console . log ( "processing call results " , changeRequests ) ;
100+ console . log ( "applying change requests " , changeRequests ) ;
85101 changeRequests . forEach ( ( { contribPoint, contribIndex, changes } ) => {
86- console . log ( "processing output of" , contribPoint , contribIndex , changes ) ;
102+ console . log (
103+ "processing change request" ,
104+ contribPoint ,
105+ contribIndex ,
106+ changes ,
107+ ) ;
87108 const contributionStatesRecord =
88109 appStore . getState ( ) . contributionStatesRecord ;
89110 const contributionStates = contributionStatesRecord [ contribPoint ] ;
90111 const contributionState = contributionStates [ contribIndex ] ;
91112 const componentModelOld = contributionState . componentModelResult . data ;
92113 let componentModel = componentModelOld ;
93- changes . forEach ( ( output ) => {
94- if ( componentModel && ( ! output . kind || output . kind === "Component" ) ) {
95- componentModel = updateComponentState ( componentModel , output ) ;
114+ changes . forEach ( ( change ) => {
115+ if ( componentModel && ( ! change . kind || change . kind === "Component" ) ) {
116+ componentModel = updateComponentState ( componentModel , change ) ;
96117 } else {
97118 // TODO: process other output kinds which may not require componentModel.
98119 console . warn (
99120 "processing of this kind of output not supported yet:" ,
100- output ,
121+ change ,
101122 ) ;
102123 }
103124 } ) ;
@@ -124,16 +145,16 @@ function applyChangeRequests(changeRequests: ChangeRequest[]) {
124145
125146function updateComponentState (
126147 componentModel : ComponentModel ,
127- output : Change ,
148+ change : Change ,
128149) : ComponentModel {
129- if ( componentModel . id === output . id ) {
130- return { ...componentModel , [ output . property ] : output . value } ;
150+ if ( componentModel . id === change . id ) {
151+ return { ...componentModel , [ change . property ] : change . value } ;
131152 } else if ( isContainerModel ( componentModel ) ) {
132153 const containerModelOld : ContainerModel = componentModel ;
133154 let containerModelNew : ContainerModel = containerModelOld ;
134155 for ( let i = 0 ; i < containerModelOld . components . length ; i ++ ) {
135156 const itemOld = containerModelOld . components [ i ] ;
136- const itemNew = updateComponentState ( itemOld , output ) ;
157+ const itemNew = updateComponentState ( itemOld , change ) ;
137158 if ( itemNew !== itemOld ) {
138159 if ( containerModelNew === containerModelOld ) {
139160 containerModelNew = {
0 commit comments