Skip to content

Commit e23f4ce

Browse files
committed
cleanup, but no fix :(
1 parent c19ec3b commit e23f4ce

File tree

7 files changed

+33
-32
lines changed

7 files changed

+33
-32
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import type { FC } from "react";
22
import { describe, it, expect, beforeEach, afterEach } from "vitest";
33
import { configureFramework, resolvePlugin } from "./configureFramework";
44
import { store } from "@/store";
5-
import { type ComponentRegistration, registry } from "@/components/registry";
5+
import { registry } from "@/components/registry";
66
import type { HostStore } from "@/types/state/host";
7-
import type { Plugin } from "@/types/state/plugin";
7+
import type { RegistrableComponent, Plugin } from "@/types/state/plugin";
88

9-
function getComponents(): [string, ComponentRegistration][] {
9+
function getComponents(): [string, RegistrableComponent][] {
1010
interface DivProps {
1111
text: string;
1212
}

chartlets.js/packages/lib/src/components/Children.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { FC } from "react";
22
import { describe, it, expect, beforeEach, afterEach } from "vitest";
33
import { render, screen } from "@testing-library/react";
44
import { registry } from "@/components/registry";
5-
import { type ComponentProps } from "./Component";
65
import { Children } from "./Children";
76

87
describe("Children", () => {
@@ -33,7 +32,7 @@ describe("Children", () => {
3332
});
3433

3534
it("should render all child types", () => {
36-
interface DivProps extends ComponentProps {
35+
interface DivProps {
3736
text: string;
3837
}
3938
const Div: FC<DivProps> = ({ text }) => <div>{text}</div>;

chartlets.js/packages/lib/src/components/Component.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect, beforeEach, afterEach } from "vitest";
22
import { render, screen } from "@testing-library/react";
3-
import { Component, type ComponentProps } from "./Component";
3+
import { Component } from "./Component";
44
import { registry } from "@/components/registry";
55
import type { FC } from "react";
66

@@ -27,7 +27,7 @@ describe("Component", () => {
2727
});
2828

2929
it("should render a known component", () => {
30-
interface DivProps extends ComponentProps {
30+
interface DivProps {
3131
text: string;
3232
}
3333
const Div: FC<DivProps> = ({ text }) => <div>{text}</div>;

chartlets.js/packages/lib/src/components/Component.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { type FC } from "react";
2-
import { type ComponentChangeHandler } from "@/types/state/event";
32
import { isString } from "@/utils/isString";
43
import { registry } from "@/components/registry";
5-
6-
export interface ComponentProps {
7-
type: string;
8-
onChange: ComponentChangeHandler;
9-
}
4+
import type { ComponentProps } from "@/types/state/plugin";
105

116
export const Component: FC<ComponentProps> = (props: ComponentProps) => {
127
const ActualComponent = isString(props.type) && registry.lookup(props.type);

chartlets.js/packages/lib/src/components/registry.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import type { ComponentType } from "react";
2-
3-
import type { ComponentProps } from "@/components/Component";
4-
5-
export type ComponentRegistration =
6-
| ComponentType<Record<string, unknown>>
7-
| ComponentType<ComponentProps>;
1+
import type { RegistrableComponent } from "@/types/state/plugin";
82

93
/**
104
* A registry for Chartlets components.
@@ -29,14 +23,14 @@ export interface Registry {
2923
* @param type The Chartlets component's unique type name.
3024
* @param component A functional React component.
3125
*/
32-
register(type: string, component: ComponentRegistration): () => void;
26+
register(type: string, component: RegistrableComponent): () => void;
3327

3428
/**
3529
* Lookup the component of the provided type.
3630
*
3731
* @param type The Chartlets component's type name.
3832
*/
39-
lookup(type: string): ComponentRegistration | undefined;
33+
lookup(type: string): RegistrableComponent | undefined;
4034

4135
/**
4236
* Clears the registry.
@@ -52,9 +46,9 @@ export interface Registry {
5246

5347
// export for testing only
5448
export class RegistryImpl implements Registry {
55-
private components = new Map<string, ComponentRegistration>();
49+
private components = new Map<string, RegistrableComponent>();
5650

57-
register(type: string, component: ComponentRegistration): () => void {
51+
register(type: string, component: RegistrableComponent): () => void {
5852
const oldComponent = this.components.get(type);
5953
this.components.set(type, component);
6054
return () => {
@@ -66,7 +60,7 @@ export class RegistryImpl implements Registry {
6660
};
6761
}
6862

69-
lookup(type: string): ComponentRegistration | undefined {
63+
lookup(type: string): RegistrableComponent | undefined {
7064
return this.components.get(type);
7165
}
7266

chartlets.js/packages/lib/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export { handleComponentChange } from "@/actions/handleComponentChange";
1414
export { updateContributionContainer } from "@/actions/updateContributionContainer";
1515

1616
// React components
17-
export { Component, type ComponentProps } from "@/components/Component";
17+
export { Component } from "@/components/Component";
1818
export { Children, type ChildrenProps } from "@/components/Children";
1919

2020
// React hooks
@@ -30,5 +30,5 @@ export {
3030

3131
// Application interface
3232
export type { HostStore, MutableHostStore } from "@/types/state/host";
33-
export type { Plugin, PluginLike } from "@/types/state/plugin";
33+
export type { ComponentProps, Plugin, PluginLike } from "@/types/state/plugin";
3434
export type { FrameworkOptions } from "@/types/state/options";

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
import type { ComponentType } from "react";
2-
import type { ComponentProps } from "@/components/Component";
2+
3+
import type { ComponentChangeHandler } from "@/types/state/event";
4+
5+
/**
6+
* Properties that custom components must support.
7+
*/
8+
export interface ComponentProps {
9+
type: string;
10+
onChange: ComponentChangeHandler;
11+
}
12+
13+
/**
14+
* A component type that is eligible for registration.
15+
*/
16+
export type RegistrableComponent =
17+
| ComponentType<object>
18+
| ComponentType<ComponentProps>;
319

420
/**
521
* A component registration - a pair comprising the component type name
622
* and the React component.
723
*/
8-
export type ComponentRegistration = [
9-
string,
10-
ComponentType<ComponentProps> | ComponentType,
11-
];
24+
export type ComponentRegistration = [string, RegistrableComponent];
1225

1326
/**
1427
* A framework plugin.

0 commit comments

Comments
 (0)