@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it } from "vitest";
22import { store } from "@/store" ;
33import {
44 getCallbackRequests ,
5+ getPropertyRefsForContribPoints ,
56 handleHostStoreChange ,
67 type PropertyRef ,
78} from "./handleHostStoreChange" ;
@@ -46,6 +47,76 @@ describe("handleHostStoreChange", () => {
4647 expect ( store . getState ( ) . themeMode ) . toEqual ( "light" ) ;
4748 } ) ;
4849
50+ it ( "should memoize computation of property refs" , ( ) => {
51+ const contributionsRecord : Record < string , ContributionState [ ] > = {
52+ panels : [
53+ {
54+ name : "p0" ,
55+ container : { title : "Panel A" } ,
56+ extension : "e0" ,
57+ componentResult : { } ,
58+ initialState : { } ,
59+ callbacks : [
60+ {
61+ function : {
62+ name : "callback" ,
63+ parameters : [ ] ,
64+ return : { } ,
65+ } ,
66+ inputs : [ { id : "@app" , property : "variableName" } ] ,
67+ outputs : [ { id : "select" , property : "value" } ] ,
68+ } ,
69+ {
70+ function : {
71+ name : "callback2" ,
72+ parameters : [ ] ,
73+ return : { } ,
74+ } ,
75+ inputs : [
76+ { id : "@app" , property : "datasetId" } ,
77+ { id : "@app" , property : "variableName" } ,
78+ ] ,
79+ outputs : [ { id : "plot" , property : "value" } ] ,
80+ } ,
81+ ] ,
82+ } ,
83+ ] ,
84+ } ;
85+ const propertyRefs1 = getPropertyRefsForContribPoints ( contributionsRecord ) ;
86+ const propertyRefs2 = getPropertyRefsForContribPoints ( contributionsRecord ) ;
87+ const propertyRefs3 = getPropertyRefsForContribPoints ( {
88+ ...contributionsRecord ,
89+ } ) ;
90+ expect ( propertyRefs1 ) . toBe ( propertyRefs2 ) ;
91+ expect ( propertyRefs2 ) . not . toBe ( propertyRefs3 ) ;
92+ expect ( propertyRefs1 ) . toEqual ( [
93+ {
94+ callbackIndex : 0 ,
95+ contribIndex : 0 ,
96+ contribPoint : "panels" ,
97+ inputIndex : 0 ,
98+ property : "variableName" ,
99+ } ,
100+ {
101+ callbackIndex : 1 ,
102+ contribIndex : 0 ,
103+ contribPoint : "panels" ,
104+ inputIndex : 0 ,
105+ property : "datasetId" ,
106+ } ,
107+ {
108+ callbackIndex : 1 ,
109+ contribIndex : 0 ,
110+ contribPoint : "panels" ,
111+ inputIndex : 1 ,
112+ property : "variableName" ,
113+ } ,
114+ ] ) ;
115+ expect ( propertyRefs1 ) . toEqual ( propertyRefs2 ) ;
116+ expect ( propertyRefs1 ) . toEqual ( propertyRefs3 ) ;
117+ expect ( propertyRefs2 ) . toEqual ( propertyRefs3 ) ;
118+ } ) ;
119+
49120 it ( "should generate callback requests" , ( ) => {
50121 const extensions = [ { name : "e0" , version : "0" , contributes : [ "panels" ] } ] ;
51122 store . setState ( {
0 commit comments