@@ -5,13 +5,9 @@ import {
55 isContainerModel ,
66 PropertyChangeEvent ,
77} from "../model/component" ;
8- import {
9- CallbackCallRequest ,
10- CallbackCallResult ,
11- ComputedOutput ,
12- } from "../model/callback" ;
8+ import { CallbackCallRequest , ChangeRequest , Change } from "../model/callback" ;
139import fetchApiResult from "../utils/fetchApiResult" ;
14- import { fetchCallbackCallResults } from "../api" ;
10+ import { fetchChangeRequests } from "../api" ;
1511import { updateArray } from "../utils/updateArray" ;
1612
1713export default function handleComponentPropertyChange (
@@ -27,6 +23,8 @@ export default function handleComponentPropertyChange(
2723 const componentPropertyValue = contribEvent . propertyValue ;
2824 const contributionModel = contributionModels [ contribIndex ] ;
2925 const callRequests : CallbackCallRequest [ ] = [ ] ;
26+ // Prepare calling all callbacks of the contribution
27+ // that are triggered by the property change
3028 ( contributionModel . callbacks || [ ] ) . forEach ( ( callback , callbackIndex ) => {
3129 if ( callback . inputs && callback . inputs . length > 0 ) {
3230 let triggerIndex : number = - 1 ;
@@ -38,11 +36,12 @@ export default function handleComponentPropertyChange(
3836 input . id === componentId &&
3937 input . property === componentPropertyName
4038 ) {
39+ // Ok - the current callback is triggered by the property change
4140 triggerIndex = inputIndex ;
4241 return componentPropertyValue ;
4342 } else {
4443 // TODO: get inputValue from other component with given id/property.
45- // For time being we use null as it is JSON-serializable
44+ // For time being we use null as it is JSON-serializable
4645 }
4746 } else {
4847 // TODO: get inputValue from other kinds.
@@ -62,44 +61,64 @@ export default function handleComponentPropertyChange(
6261 }
6362 }
6463 } ) ;
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+ } ;
6576 console . debug ( "callRequests" , callRequests ) ;
66- if ( callRequests . length ) {
67- fetchApiResult ( fetchCallbackCallResults , callRequests ) . then (
68- ( callResultResult ) => {
69- if ( callResultResult . data ) {
70- applyCallbackCallResults ( callResultResult . data ) ;
77+ if ( callRequests . length == 0 ) {
78+ applyChangeRequests ( [ originalChangeRequest ] ) ;
79+ } else {
80+ fetchApiResult ( fetchChangeRequests , callRequests ) . then (
81+ ( changeRequestsResult ) => {
82+ if ( changeRequestsResult . data ) {
83+ applyChangeRequests (
84+ [ originalChangeRequest ] . concat ( changeRequestsResult . data ) ,
85+ ) ;
7186 } else {
72- console . error ( "callback failed:" , callResultResult . error ) ;
73- console . error ( " for requests:" , callRequests ) ;
87+ console . error (
88+ "callback failed:" ,
89+ changeRequestsResult . error ,
90+ "for call requests:" ,
91+ callRequests ,
92+ ) ;
7493 }
7594 } ,
7695 ) ;
7796 }
7897}
7998
80- function applyCallbackCallResults ( callResults : CallbackCallResult [ ] ) {
81- console . log ( "processing call results " , callResults ) ;
82- callResults . forEach ( ( { contribPoint, contribIndex, computedOutputs } ) => {
99+ function applyChangeRequests ( changeRequests : ChangeRequest [ ] ) {
100+ console . log ( "applying change requests " , changeRequests ) ;
101+ changeRequests . forEach ( ( { contribPoint, contribIndex, changes } ) => {
83102 console . log (
84- "processing output of " ,
103+ "processing change request " ,
85104 contribPoint ,
86105 contribIndex ,
87- computedOutputs ,
106+ changes ,
88107 ) ;
89108 const contributionStatesRecord =
90109 appStore . getState ( ) . contributionStatesRecord ;
91110 const contributionStates = contributionStatesRecord [ contribPoint ] ;
92111 const contributionState = contributionStates [ contribIndex ] ;
93112 const componentModelOld = contributionState . componentModelResult . data ;
94113 let componentModel = componentModelOld ;
95- computedOutputs . forEach ( ( output ) => {
96- if ( componentModel && ( ! output . kind || output . kind === "Component" ) ) {
97- componentModel = updateComponentState ( componentModel , output ) ;
114+ changes . forEach ( ( change ) => {
115+ if ( componentModel && ( ! change . kind || change . kind === "Component" ) ) {
116+ componentModel = updateComponentState ( componentModel , change ) ;
98117 } else {
99118 // TODO: process other output kinds which may not require componentModel.
100119 console . warn (
101120 "processing of this kind of output not supported yet:" ,
102- output ,
121+ change ,
103122 ) ;
104123 }
105124 } ) ;
@@ -126,16 +145,16 @@ function applyCallbackCallResults(callResults: CallbackCallResult[]) {
126145
127146function updateComponentState (
128147 componentModel : ComponentModel ,
129- output : ComputedOutput ,
148+ change : Change ,
130149) : ComponentModel {
131- if ( componentModel . id === output . id ) {
132- return { ...componentModel , [ output . property ] : output . value } ;
150+ if ( componentModel . id === change . id ) {
151+ return { ...componentModel , [ change . property ] : change . value } ;
133152 } else if ( isContainerModel ( componentModel ) ) {
134153 const containerModelOld : ContainerModel = componentModel ;
135154 let containerModelNew : ContainerModel = containerModelOld ;
136155 for ( let i = 0 ; i < containerModelOld . components . length ; i ++ ) {
137156 const itemOld = containerModelOld . components [ i ] ;
138- const itemNew = updateComponentState ( itemOld , output ) ;
157+ const itemNew = updateComponentState ( itemOld , change ) ;
139158 if ( itemNew !== itemOld ) {
140159 if ( containerModelNew === containerModelOld ) {
141160 containerModelNew = {
0 commit comments