Skip to content

Commit 989b2ab

Browse files
committed
fixed linting issues
1 parent 661b088 commit 989b2ab

File tree

3 files changed

+29
-34
lines changed

3 files changed

+29
-34
lines changed
Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useCallback, useMemo } from "react";
2-
import { TopLevelSpec } from "vega-lite";
2+
import type { TopLevelSpec } from "vega-lite";
33

4-
import { ComponentChangeHandler } from "@/lib/types/state/event";
4+
import type { ComponentChangeHandler } from "@/lib/types/state/event";
55
import { isObject } from "@/lib/utils/isObject";
66
import { isString } from "@/lib/utils/isString";
77

@@ -28,25 +28,25 @@ export function useSignalListeners(
2828
type: string,
2929
id: string | undefined,
3030
onChange: ComponentChangeHandler,
31-
): { [key: string]: SignalHandler } {
31+
): Record<string, SignalHandler> {
3232
/*
3333
* Here, we create map of signals which will be then used to create the
3434
* map of signal-listeners because not all params are event-listeners, and we
3535
* need to identify them. Later in the code, we then see which handlers do we
3636
* have so that we can create those listeners with the `name` specified in
3737
* the event-listener object.
3838
*/
39-
const signals = useMemo(() => {
40-
if (!chart) {
41-
return {};
39+
const signalNames = useMemo((): Record<string, string> => {
40+
const signalNames: Record<string, string> = {};
41+
if (!chart || !chart.params) {
42+
return signalNames;
4243
}
43-
if (!chart.params) {
44-
return {};
45-
}
46-
return chart.params.filter(isSelectionParameter).reduce((acc, param) => {
47-
acc[param.select.on] = param.name;
48-
return acc;
49-
}, {});
44+
return chart.params
45+
.filter(isSelectionParameter)
46+
.reduce((paramNames, param) => {
47+
paramNames[param.select.on] = param.name;
48+
return paramNames;
49+
}, signalNames);
5050
}, [chart]);
5151

5252
const handleClickSignal = useCallback(
@@ -63,32 +63,29 @@ export function useSignalListeners(
6363
[id, onChange, type],
6464
);
6565

66-
/*
67-
* Currently, we only have click events support, but if more are required,
68-
* they can be implemented and added in the map below.
69-
*/
70-
const signalHandlerMap: { [key: string]: SignalHandler } = useMemo(
71-
() => ({
72-
click: handleClickSignal,
73-
}),
74-
[handleClickSignal],
75-
);
76-
7766
/*
7867
* Creates the map of signal listeners based on
7968
* the `signals` map computed above.
8069
*/
8170
return useMemo(() => {
82-
const signalListeners = {};
83-
Object.entries(signals).forEach(([event, signalName]) => {
84-
if (signalHandlerMap[event]) {
85-
signalListeners[signalName] = signalHandlerMap[event];
71+
/*
72+
* Currently, we only have click events support, but if more are required,
73+
* they can be implemented and added in the map below.
74+
*/
75+
const signalHandlers: Record<string, SignalHandler> = {
76+
click: handleClickSignal,
77+
};
78+
79+
const signalListeners: Record<string, SignalHandler> = {};
80+
Object.entries(signalNames).forEach(([event, signalName]) => {
81+
if (signalHandlers[event]) {
82+
signalListeners[signalName] = signalHandlers[event];
8683
} else {
8784
console.warn(
8885
`The signal "${event}" is not yet supported in chartlets.js`,
8986
);
9087
}
9188
});
9289
return signalListeners;
93-
}, [signals]);
90+
}, [signalNames, handleClickSignal]);
9491
}

chartlets.js/src/lib/hooks.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import type { StoreState } from "@/lib/types/state/store";
22
import { store } from "@/lib/store";
3-
import { useCallback, useMemo } from "react";
3+
import { useMemo } from "react";
44
import type { ContributionState } from "@/lib/types/state/contribution";
5-
import { type SignalHandler } from "@/lib/components/Plot/vega";
6-
import type { TopLevelSpec } from "vega-lite";
75
import type {
86
ComponentChangeEvent,
97
ComponentChangeHandler,
108
} from "@/lib/types/state/event";
119
import { handleComponentChange } from "@/lib/actions/handleComponentChange";
12-
import { isString } from "@/lib/utils/isString";
13-
import { isObject } from "@/lib/utils/isObject";
1410

1511
const selectConfiguration = (state: StoreState) => state.configuration;
1612

chartlets.py/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## Version 0.0.30 (in development)
2+
13
* The `Plot` component now respects a `theme` property. If not given,
24
it will respect the current MUI theme mode `"dark"`.
35

0 commit comments

Comments
 (0)