Skip to content

Commit b78cce9

Browse files
committed
update based on reviwers comments
1 parent 70452a6 commit b78cce9

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

chartlets.js/packages/lib/src/actions/handleHostStoreChange.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import memoize from "fast-memoize";
2020
export interface PropertyRef extends ContribRef, CallbackRef, InputRef {
2121
/** The property. */
2222
property: string;
23-
/** Property ID for memoization */
24-
id: string;
2523
}
2624

2725
export function handleHostStoreChange() {
@@ -74,29 +72,34 @@ export function getCallbackRequests(
7472
);
7573
}
7674

75+
// This is a dummy function created to memoize the _inputValues values
76+
const _getInputValues = (_inputValues: unknown[]): unknown[] => {
77+
return _inputValues;
78+
};
79+
const memoizedInputValues = memoize(_getInputValues);
80+
7781
const getCallbackRequest = (
7882
propertyRef: PropertyRef,
7983
lastCallbackInputValues: Record<string, unknown[]> | undefined,
8084
contributionsRecord: Record<string, ContributionState[]>,
8185
hostStore: HostStore,
8286
) => {
83-
const contributions = contributionsRecord[propertyRef.contribPoint];
84-
const contribution = contributions[propertyRef.contribIndex];
85-
const callback = contribution.callbacks![propertyRef.callbackIndex];
87+
const contribPoint: string = propertyRef.contribPoint;
88+
const contribIndex: number = propertyRef.contribIndex;
89+
const callbackIndex: number = propertyRef.callbackIndex;
90+
const inputIndex: number = propertyRef.inputIndex;
91+
const contributions = contributionsRecord[contribPoint];
92+
const contribution = contributions[contribIndex];
93+
const callback = contribution.callbacks![callbackIndex];
8694
const _inputValues = getInputValues(
8795
callback.inputs!,
8896
contribution,
8997
hostStore,
9098
);
9199

92-
// This is a dummy function created to memoize the _inputValues values
93-
const _getInputValues = (_inputValues: unknown[]): unknown[] => {
94-
return _inputValues;
95-
};
96-
const memoizedInputValues = memoize(_getInputValues);
97100
const inputValues = memoizedInputValues(_inputValues);
98101

99-
const propRefId = propertyRef.id;
102+
const propRefId = `${contribPoint}-${contribIndex}-${callbackIndex}-${inputIndex}`;
100103
if (lastCallbackInputValues) {
101104
const lastInputValues = lastCallbackInputValues[propRefId];
102105
if (lastInputValues && shallowEqualArrays(lastInputValues, inputValues)) {
@@ -142,7 +145,6 @@ function getHostStorePropertyRefs(): PropertyRef[] {
142145
callbackIndex,
143146
inputIndex,
144147
property: formatObjPath(input.property),
145-
id: `${contribPoint}-${contribIndex}-${callbackIndex}-${inputIndex}`,
146148
});
147149
}
148150
}),

chartlets.js/packages/lib/src/actions/handleHostStoreChanges.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ describe("handleHostStoreChange", () => {
161161
});
162162
const propertyRefs: PropertyRef[] = [
163163
{
164-
id: "panel-0-0-0",
165164
contribPoint: "panel",
166165
contribIndex: 0,
167166
callbackIndex: 0,

0 commit comments

Comments
 (0)