@@ -7,7 +7,6 @@ import type {
77 ContribRef ,
88 InputRef ,
99} from "@/types/model/callback" ;
10- import type { Input } from "@/types/model/channel" ;
1110import { getInputValues } from "@/actions/helpers/getInputValues" ;
1211import { formatObjPath } from "@/utils/objPath" ;
1312import { invokeCallbacks } from "@/actions/helpers/invokeCallbacks" ;
@@ -37,7 +36,7 @@ export function handleHostStoreChange() {
3736 // Exit if there are no extensions (yet)
3837 return ;
3938 }
40- const propertyRefs = getHostStorePropertyRefs ( contributionsRecord ) ;
39+ const propertyRefs = getPropertyRefsForContribPoints ( contributionsRecord ) ;
4140 if ( ! propertyRefs || propertyRefs . length === 0 ) {
4241 // Exit if there are is nothing to be changed
4342 return ;
@@ -71,18 +70,64 @@ function getCallbackRequests(
7170}
7271
7372/**
74- * Get the static list of host state property references for all contributions.
73+ * Get the static list of host state property references
74+ * for given contribution points.
7575 */
76- const getHostStorePropertyRefs = memoize ( _getHostStorePropertyRefs ) ;
76+ const getPropertyRefsForContribPoints = memoize (
77+ _getPropertyRefsForContribPoints ,
78+ ) ;
7779
78- function getCallbackfn (
80+ function _getPropertyRefsForContribPoints (
81+ contributionsRecord : Record < ContribPoint , ContributionState [ ] > ,
82+ ) : PropertyRef [ ] {
83+ const propertyRefs : PropertyRef [ ] = [ ] ;
84+ Object . getOwnPropertyNames ( contributionsRecord ) . forEach ( ( contribPoint ) => {
85+ const contributions = contributionsRecord [ contribPoint ] ;
86+ propertyRefs . push (
87+ ...getPropertyRefsForContributions ( contribPoint , contributions ) ,
88+ ) ;
89+ } ) ;
90+ return propertyRefs ;
91+ }
92+
93+ /**
94+ * Get the static list of host state property references
95+ * for given contributions.
96+ */
97+ const getPropertyRefsForContributions = memoize (
98+ _getPropertyRefsForContributions ,
99+ ) ;
100+
101+ function _getPropertyRefsForContributions (
102+ contribPoint : string ,
103+ contributions : ContributionState [ ] ,
104+ ) : PropertyRef [ ] {
105+ const propertyRefs : PropertyRef [ ] = [ ] ;
106+ contributions . forEach ( ( contribution , contribIndex ) => {
107+ propertyRefs . push (
108+ ...getPropertyRefsForCallbacks (
109+ contribPoint ,
110+ contribIndex ,
111+ contribution . callbacks ,
112+ ) ,
113+ ) ;
114+ } ) ;
115+ return propertyRefs ;
116+ }
117+
118+ /**
119+ * Get the static list of host state property references
120+ * for given callbacks.
121+ */
122+ const getPropertyRefsForCallbacks = memoize ( _getPropertyRefsForCallbacks ) ;
123+
124+ function _getPropertyRefsForCallbacks (
79125 contribPoint : string ,
80- contribution : ContributionState ,
81126 contribIndex : number ,
127+ callbacks : Callback [ ] | undefined ,
82128) {
83129 const propertyRefs : PropertyRef [ ] = [ ] ;
84- const callbacks : Callback [ ] = contribution . callbacks || [ ] ;
85- callbacks . forEach ( ( callback , callbackIndex ) => {
130+ ( callbacks || [ ] ) . forEach ( ( callback , callbackIndex ) => {
86131 const inputs = callback . inputs || [ ] ;
87132 inputs . forEach ( ( input , inputIndex ) => {
88133 if ( ! input . noTrigger && input . id === "@app" && input . property ) {
@@ -99,17 +144,6 @@ function getCallbackfn(
99144 return propertyRefs ;
100145}
101146
102- function _getHostStorePropertyRefs (
103- contributionsRecord : Record < ContribPoint , ContributionState [ ] > ,
104- ) : PropertyRef [ ] {
105- const propertyRefs : PropertyRef [ ] = [ ] ;
106- Object . getOwnPropertyNames ( contributionsRecord ) . forEach ( ( contribPoint ) => {
107- const contributions = contributionsRecord [ contribPoint ] ;
108- contributions . forEach ( getCallbackfn ( propertyRefs , contribPoint ) ) ;
109- } ) ;
110- return propertyRefs ;
111- }
112-
113147function synchronizeThemeMode ( hostStore : HostStore ) {
114148 const newThemeMode = hostStore . get ( "themeMode" ) ;
115149 const oldThemeMode = store . getState ( ) . themeMode ;
0 commit comments