Skip to content

Commit 77ae7c1

Browse files
committed
fix registry --> 0.0.25
1 parent 1140346 commit 77ae7c1

File tree

6 files changed

+35
-20
lines changed

6 files changed

+35
-20
lines changed

chartlets.js/CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Version 0.0.25 (from 2024/11/23)
2+
3+
* `Registry.register()` now requires the `type`
4+
to be passed as 1st argument because `component.name` will
5+
be a mangled name in most cases.
6+
17
## Version 0.0.24 (from 2024/11/23)
28

39
* Exporting required `HostStore` type.

chartlets.js/package-lock.json

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

chartlets.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chartlets",
3-
"version": "0.0.24",
3+
"version": "0.0.25",
44
"description": "An experimental library for integrating interactive charts into existing JavaScript applications.",
55
"type": "module",
66
"files": [

chartlets.js/src/lib/component/Registry.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ describe("Test that RegistryImpl", () => {
1010
const A = () => void 0;
1111
const B = () => void 0;
1212
const C = () => void 0;
13-
const unregisterA = registry.register(A);
14-
const unregisterB = registry.register(B);
15-
const unregisterC = registry.register(C);
13+
const unregisterA = registry.register("A", A);
14+
const unregisterB = registry.register("B", B);
15+
const unregisterC = registry.register("C", C);
1616

1717
expect(registry.lookup("A")).toBe(A);
1818
expect(registry.lookup("B")).toBe(B);
@@ -32,7 +32,7 @@ describe("Test that RegistryImpl", () => {
3232
expect(new Set(registry.types)).toEqual(new Set(["C"]));
3333

3434
const C2 = () => void 0;
35-
const unregisterC2 = registry.register(C2, "C");
35+
const unregisterC2 = registry.register("C", C2);
3636
expect(registry.lookup("A")).toBeUndefined();
3737
expect(registry.lookup("B")).toBeUndefined();
3838
expect(registry.lookup("C")).toBe(C2);

chartlets.js/src/lib/component/Registry.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@ export interface Registry {
88
/**
99
* Register a React component that renders a Chartlets component.
1010
*
11+
* `component` must be a functional React component with at
12+
* least the following two component props:
13+
*
14+
* - `type: string`: your component's type name.
15+
* This will be the same as the `type` used for registration.
16+
* - `onChange: ComponentChangeHandler`: an event handler
17+
* that your component may call to signal change events.
18+
*
19+
* Both props are always be present plus. The component may also
20+
* be passed any other props provided by the contribution.
21+
*
22+
* @param type The Chartlets component's unique type name.
1123
* @param component A functional React component.
12-
* @param type The Chartlets component's type name.
13-
* If not provided, `component.name` is used.
1424
*/
15-
register(component: FC<ComponentProps>, type?: string): () => void;
25+
register(type: string, component: FC<ComponentProps>): () => void;
1626

1727
/**
1828
* Lookup the component of the provided type.
@@ -31,8 +41,7 @@ export interface Registry {
3141
export class RegistryImpl implements Registry {
3242
private components = new Map<string, FC<ComponentProps>>();
3343

34-
register(component: FC<ComponentProps>, type?: string): () => void {
35-
type = type || component.name;
44+
register(type: string, component: FC<ComponentProps>): () => void {
3645
const oldComponent = this.components.get(type);
3746
this.components.set(type, component);
3847
return () => {
@@ -56,7 +65,7 @@ export class RegistryImpl implements Registry {
5665
/**
5766
* The Chartly component registry.
5867
*
59-
* Use `registry.register(C)` to register your own component `C`.
68+
* Use `registry.register("C", C)` to register your own component `C`.
6069
*
6170
* `C` must be a functional React component with at least the following
6271
* two properties:

chartlets.js/src/lib/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ import { Plot } from "@/lib/components/Plot";
4747
import { Select } from "@/lib/components/Select";
4848
import { Typography } from "@/lib/components/Typography";
4949

50-
registry.register(Box);
51-
registry.register(Button);
52-
registry.register(Checkbox);
53-
registry.register(CircularProgress);
54-
registry.register(Plot);
55-
registry.register(Select);
56-
registry.register(Typography);
50+
registry.register("Box", Box);
51+
registry.register("Button", Button);
52+
registry.register("Checkbox", Checkbox);
53+
registry.register("CircularProgress", CircularProgress);
54+
registry.register("Plot", Plot);
55+
registry.register("Select", Select);
56+
registry.register("Typography", Typography);

0 commit comments

Comments
 (0)