1- import memoizeOne from "memoize-one" ;
2-
31import { store } from "@/lib/store" ;
42import type {
53 CallbackRef ,
@@ -9,16 +7,16 @@ import type {
97} from "@/lib/types/model/callback" ;
108import type { Input } from "@/lib/types/model/channel" ;
119import { getInputValues } from "@/lib/actions/helpers/getInputValues" ;
12- import { getValue , type PropertyPath } from "@/lib/utils/getValue " ;
10+ import { getValue , type ObjPath , toObjPath } from "@/lib/utils/objPath " ;
1311import { invokeCallbacks } from "@/lib/actions/helpers/invokeCallbacks" ;
14- import type { ContributionState } from "@/lib" ;
12+ import type { ContributionState } from "@/lib/types/state/contribution " ;
1513
1614/**
1715 * A reference to a property of an input of a callback of a contribution.
1816 */
1917export interface PropertyRef extends ContribRef , CallbackRef , InputRef {
2018 /** The property name as path. */
21- propertyPath : PropertyPath ;
19+ propertyPath : ObjPath ;
2220}
2321
2422export function handleHostStoreChange < S extends object = object > (
@@ -39,30 +37,29 @@ function getCallbackRequests<S extends object = object>(
3937 hostState : S ,
4038 prevHostState : S ,
4139) : CallbackRequest [ ] {
42- const propertyRefs = getHostStorePropertyRefs ( ) . filter ( ( propertyRef ) =>
43- hasPropertyChanged ( propertyRef . propertyPath , hostState , prevHostState ) ,
44- ) ;
45- const callbackRequest : CallbackRequest [ ] = [ ] ;
46- propertyRefs . forEach ( ( propertyRef ) => {
47- const contributions = contributionsRecord [ propertyRef . contribPoint ] ;
48- const contribution = contributions [ propertyRef . contribIndex ] ;
49- const callback = contribution . callbacks ! [ propertyRef . callbackIndex ] ;
50- const inputValues = getInputValues (
51- callback . inputs ! ,
52- contribution ,
53- hostState ,
54- ) ;
55- callbackRequest . push ( { ...propertyRef , inputValues } ) ;
56- } ) ;
57- return callbackRequest ;
40+ return getHostStorePropertyRefs ( )
41+ . filter ( ( propertyRef ) =>
42+ hasPropertyChanged ( propertyRef . propertyPath , hostState , prevHostState ) ,
43+ )
44+ . map ( ( propertyRef ) => {
45+ const contributions = contributionsRecord [ propertyRef . contribPoint ] ;
46+ const contribution = contributions [ propertyRef . contribIndex ] ;
47+ const callback = contribution . callbacks ! [ propertyRef . callbackIndex ] ;
48+ const inputValues = getInputValues (
49+ callback . inputs ! ,
50+ contribution ,
51+ hostState ,
52+ ) ;
53+ return { ...propertyRef , inputValues } ;
54+ } ) ;
5855}
5956
60- const getHostStorePropertyRefs = memoizeOne ( _getHostStorePropertyRefs ) ;
57+ // const getHostStorePropertyRefs = memoizeOne(_getHostStorePropertyRefs);
6158
6259/**
6360 * Get the static list of host state property references for all contributions.
6461 */
65- function _getHostStorePropertyRefs ( ) : PropertyRef [ ] {
62+ function getHostStorePropertyRefs ( ) : PropertyRef [ ] {
6663 const { contributionsRecord } = store . getState ( ) ;
6764 const propertyRefs : PropertyRef [ ] = [ ] ;
6865 Object . getOwnPropertyNames ( contributionsRecord ) . forEach ( ( contribPoint ) => {
@@ -77,7 +74,7 @@ function _getHostStorePropertyRefs(): PropertyRef[] {
7774 contribIndex,
7875 callbackIndex,
7976 inputIndex,
80- propertyPath : input . property ! . split ( "." ) ,
77+ propertyPath : toObjPath ( input . property ! ) ,
8178 } ) ;
8279 }
8380 } ) ,
@@ -89,7 +86,7 @@ function _getHostStorePropertyRefs(): PropertyRef[] {
8986}
9087
9188function hasPropertyChanged < S extends object = object > (
92- propertyPath : PropertyPath ,
89+ propertyPath : ObjPath ,
9390 currState : S ,
9491 prevState : S ,
9592) : boolean {
0 commit comments