@@ -13,14 +13,13 @@ import { PropertyChangeEvent } from "../model/event";
1313
1414import { ContribPoint } from "../model/extension" ;
1515
16- export default function handleComponentPropertyChange (
16+ export default function applyPropertyChange (
1717 contribPoint : ContribPoint ,
1818 contribIndex : number ,
1919 contribEvent : PropertyChangeEvent ,
2020) {
21- const appState = appStore . getState ( ) ;
22- const contributionModels =
23- appState . contributionsRecordResult . data ! [ contribPoint ] ;
21+ const { contributionModelsRecord } = appStore . getState ( ) ;
22+ const contributionModels = contributionModelsRecord [ contribPoint ] ;
2423 const componentId = contribEvent . componentId ;
2524 const componentPropertyName = contribEvent . propertyName ;
2625 const componentPropertyValue = contribEvent . propertyValue ;
@@ -108,15 +107,14 @@ function applyChangeRequests(changeRequests: ChangeRequest[]) {
108107 contribIndex ,
109108 changes ,
110109 ) ;
111- const contributionStatesRecord =
112- appStore . getState ( ) . contributionStatesRecord ;
110+ const { contributionStatesRecord } = appStore . getState ( ) ;
113111 const contributionStates = contributionStatesRecord [ contribPoint ] ;
114112 const contributionState = contributionStates [ contribIndex ] ;
115- const componentModelOld = contributionState . componentState ;
116- let componentModel = componentModelOld ;
113+ const componentStateOld = contributionState . componentState ;
114+ let componentState = componentStateOld ;
117115 changes . forEach ( ( change ) => {
118- if ( componentModel && ( ! change . kind || change . kind === "Component" ) ) {
119- componentModel = updateComponentState ( componentModel , change ) ;
116+ if ( componentState && ( ! change . kind || change . kind === "Component" ) ) {
117+ componentState = applyComponentStateChange ( componentState , change ) ;
120118 } else {
121119 // TODO: process other output kinds which may not require componentModel.
122120 console . warn (
@@ -125,47 +123,44 @@ function applyChangeRequests(changeRequests: ChangeRequest[]) {
125123 ) ;
126124 }
127125 } ) ;
128- if ( componentModel && componentModel !== componentModelOld ) {
126+ if ( componentState && componentState !== componentStateOld ) {
129127 appStore . setState ( {
130128 contributionStatesRecord : {
131129 ...contributionStatesRecord ,
132130 [ contribPoint ] : updateArray < ContributionState > (
133131 contributionStates ,
134132 contribIndex ,
135- {
136- ...contributionState ,
137- componentState : componentModel ,
138- } ,
133+ { ...contributionState , componentState } ,
139134 ) ,
140135 } ,
141136 } ) ;
142137 }
143138 } ) ;
144139}
145140
146- function updateComponentState (
147- componentModel : ComponentState ,
141+ function applyComponentStateChange (
142+ componentState : ComponentState ,
148143 change : Change ,
149144) : ComponentState {
150- if ( componentModel . id === change . id ) {
151- return { ...componentModel , [ change . property ] : change . value } ;
152- } else if ( isContainerState ( componentModel ) ) {
153- const containerModelOld : ContainerState = componentModel ;
154- let containerModelNew : ContainerState = containerModelOld ;
155- for ( let i = 0 ; i < containerModelOld . components . length ; i ++ ) {
156- const itemOld = containerModelOld . components [ i ] ;
157- const itemNew = updateComponentState ( itemOld , change ) ;
145+ if ( componentState . id === change . id ) {
146+ return { ...componentState , [ change . property ] : change . value } ;
147+ } else if ( isContainerState ( componentState ) ) {
148+ const containerStateOld : ContainerState = componentState ;
149+ let containerStateNew : ContainerState = containerStateOld ;
150+ for ( let i = 0 ; i < containerStateOld . components . length ; i ++ ) {
151+ const itemOld = containerStateOld . components [ i ] ;
152+ const itemNew = applyComponentStateChange ( itemOld , change ) ;
158153 if ( itemNew !== itemOld ) {
159- if ( containerModelNew === containerModelOld ) {
160- containerModelNew = {
161- ...containerModelOld ,
162- components : [ ...containerModelOld . components ] ,
154+ if ( containerStateNew === containerStateOld ) {
155+ containerStateNew = {
156+ ...containerStateOld ,
157+ components : [ ...containerStateOld . components ] ,
163158 } ;
164159 }
165- containerModelNew . components [ i ] = itemNew ;
160+ containerStateNew . components [ i ] = itemNew ;
166161 }
167162 }
168- return containerModelNew ;
163+ return containerStateNew ;
169164 }
170- return componentModel ;
165+ return componentState ;
171166}
0 commit comments