@@ -12,7 +12,6 @@ import type { ContributionState } from "@/types/state/contribution";
1212import type { HostStore } from "@/types/state/host" ;
1313import { store } from "@/store" ;
1414import { shallowEqualArrays } from "@/utils/compare" ;
15- import memoize from "fast-memoize" ;
1615
1716/**
1817 * A reference to a property of an input of a callback of a contribution.
@@ -72,16 +71,9 @@ export function getCallbackRequests(
7271 ) ;
7372}
7473
75- // This is a dummy function created to memoize the _inputValues values from
76- // getCallbackRequest()
77- const _getInputValues = ( _inputValues : unknown [ ] ) : unknown [ ] => {
78- return _inputValues ;
79- } ;
80- const memoizedInputValues = memoize ( _getInputValues ) ;
81-
8274const getCallbackRequest = (
8375 propertyRef : PropertyRef ,
84- lastCallbackInputValues : Record < string , unknown [ ] > | undefined ,
76+ lastCallbackInputValues : Record < string , unknown [ ] > ,
8577 contributionsRecord : Record < string , ContributionState [ ] > ,
8678 hostStore : HostStore ,
8779) => {
@@ -91,32 +83,23 @@ const getCallbackRequest = (
9183 const contributions = contributionsRecord [ contribPoint ] ;
9284 const contribution = contributions [ contribIndex ] ;
9385 const callback = contribution . callbacks ! [ callbackIndex ] ;
94- const _inputValues = getInputValues (
95- callback . inputs ! ,
96- contribution ,
97- hostStore ,
98- ) ;
99-
100- const inputValues = memoizedInputValues ( _inputValues ) ;
101-
86+ const inputValues = getInputValues ( callback . inputs ! , contribution , hostStore ) ;
10287 const callbackId = `${ contribPoint } -${ contribIndex } -${ callbackIndex } ` ;
103- if ( lastCallbackInputValues ) {
104- const lastInputValues = lastCallbackInputValues [ callbackId ] ;
105- if ( lastInputValues && shallowEqualArrays ( lastInputValues , inputValues ) ) {
106- // We no longer log, as the situation is quite common
107- // Enable error logging for debugging only:
108- // console.groupCollapsed("Skipping callback request");
109- // console.debug("inputValues", inputValues);
110- // console.groupEnd();
111- return undefined ;
112- }
113- lastCallbackInputValues [ callbackId ] = inputValues ;
114- store . setState ( {
115- lastCallbackInputValues : { ...lastCallbackInputValues } ,
116- } ) ;
117- } else {
118- store . setState ( { lastCallbackInputValues : { [ callbackId ] : inputValues } } ) ;
88+ const lastInputValues = lastCallbackInputValues [ callbackId ] ;
89+ if ( shallowEqualArrays ( lastInputValues , inputValues ) ) {
90+ // We no longer log, as the situation is quite common
91+ // Enable error logging for debugging only:
92+ // console.groupCollapsed("Skipping callback request");
93+ // console.debug("inputValues", inputValues);
94+ // console.groupEnd();
95+ return undefined ;
11996 }
97+ store . setState ( {
98+ lastCallbackInputValues : {
99+ ...lastCallbackInputValues ,
100+ [ callbackId ] : inputValues ,
101+ } ,
102+ } ) ;
120103 return { ...propertyRef , inputValues } ;
121104} ;
122105
0 commit comments