Skip to content

Commit 7a49490

Browse files
committed
update based on reviewers comments
1 parent 86809c8 commit 7a49490

File tree

4 files changed

+18
-43
lines changed

4 files changed

+18
-43
lines changed

chartlets.js/package-lock.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chartlets.js/packages/lib/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"preview": "vite preview"
5656
},
5757
"dependencies": {
58-
"fast-memoize": "^2.5.2",
5958
"microdiff": "^1.4",
6059
"zustand": "^5.0"
6160
},

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

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type { ContributionState } from "@/types/state/contribution";
1212
import type { HostStore } from "@/types/state/host";
1313
import { store } from "@/store";
1414
import { 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-
8274
const 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

chartlets.js/packages/lib/src/types/state/store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ export interface StoreState {
2828
/**
2929
* Store last input values for callback requests to avoid invoking them if
3030
* there are no state changes
31-
* */
32-
lastCallbackInputValues?: Record<string, unknown[]>;
31+
*/
32+
lastCallbackInputValues: Record<string, unknown[]>;
3333
}

0 commit comments

Comments
 (0)