@@ -13,6 +13,7 @@ import {
13
13
has ,
14
14
intersection ,
15
15
isEmpty ,
16
+ isNil ,
16
17
keys ,
17
18
lensPath ,
18
19
merge ,
@@ -425,7 +426,7 @@ function updateOutput(
425
426
changedPropIds,
426
427
} ;
427
428
428
- const { inputs, state} = dependenciesRequest . content . find (
429
+ const { inputs, state, client_function } = dependenciesRequest . content . find (
429
430
dependency => dependency . output === outputIdAndProp
430
431
) ;
431
432
const validKeys = keys ( getState ( ) . paths ) ;
@@ -496,6 +497,53 @@ function updateOutput(
496
497
} ) ;
497
498
}
498
499
500
+ // Clientside hook
501
+ if ( ! isNil ( client_function ) && ! isEmpty ( client_function ) ) {
502
+
503
+ const returnValue = (
504
+ window [ client_function . namespace ] [ client_function . function_name ] (
505
+ ...( has ( 'inputs' , payload ) ? pluck ( 'value' , payload . inputs ) : [ ] ) ,
506
+ ...( has ( 'state' , payload ) ? pluck ( 'value' , payload . state ) : [ ] )
507
+ )
508
+ ) ;
509
+
510
+ const [ outputId , outputProp ] = payload . output . split ( '.' ) ;
511
+ const updatedProps = {
512
+ [ outputProp ] : returnValue
513
+ } ;
514
+
515
+ /*
516
+ * Update the request queue by treating a successful clientside
517
+ * like a succesful serverside response (200 status code)
518
+ */
519
+ updateRequestQueue ( false , STATUS . OK ) ;
520
+
521
+ // Update the layout with the new result
522
+ dispatch ( updateProps ( {
523
+ itempath : getState ( ) . paths [ outputId ] ,
524
+ props : updatedProps ,
525
+ source : 'response'
526
+ } ) ) ;
527
+
528
+ /*
529
+ * This output could itself be a serverside or clientside input
530
+ * to another function
531
+ */
532
+ dispatch ( notifyObservers ( {
533
+ id : outputId ,
534
+ props : updatedProps
535
+ } ) ) ;
536
+
537
+ /*
538
+ * Note that unlike serverside updates, we're not handling
539
+ * children as components right now, so we don't need to
540
+ * crawl the computed result to check for nested components
541
+ * or properties that might trigger other inputs.
542
+ * In the future, we could handle this case.
543
+ */
544
+ return ;
545
+ }
546
+
499
547
if ( hooks . request_pre !== null ) {
500
548
hooks . request_pre ( payload ) ;
501
549
}
0 commit comments