@chronocide/hyper 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -43,23 +43,22 @@ document.body.appendChild(img);
43
43
 
44
44
  List items can be cached using `list`, only updated if the data is changed; order does not matter. Data does not need to be unique, as duplicate nodes are cloned.
45
45
 
46
- ```ts
47
- import type { Component } from '@chronocide/hyper';
46
+ **Note**, `list` only supports `string` and `number` type.
48
47
 
48
+ ```ts
49
49
  import h, { list } from '@chronocide/hyper';
50
50
 
51
51
  type Planet = { id: string; name: string };
52
52
 
53
- const planets: Planet[] = [
54
- { id: 'jupiter', name: 'Jupiter' },
55
- { id: 'mars', name: 'Mars' },
56
- { id: 'pluto', name: 'Pluto' }
57
- ];
53
+ const planets = new Map<string, Planet>();
54
+ planets.add('jupiter', { id: 'jupiter', name: 'Jupiter' });
55
+ planets.add('mars', { id: 'mars', name: 'Mars' });
56
+ planets.add('pluto', { id: 'pluto', name: 'Pluto' });
58
57
 
59
58
  const ul = h('ul')()(); // <ul></ul>
60
- const component: Component<Planet> = planet => h('li')()(planet.name);
59
+ const render = (id: string) => h('li')()(planets.get(id)?.name ?? '-');
61
60
 
62
- const update = list<Planet>(component)(ul);
61
+ const update = list(render)(ul);
63
62
  update(planets); // <ul><li>Jupiter</li><li>Mars</li><li>Pluto</li></ul>
64
63
  ```
65
64
 
package/dist/hyper.d.ts CHANGED
@@ -15,7 +15,7 @@ declare const _default: <T extends keyof HTMLElementTagNameMap>(tag: T) => <P ex
15
15
  declare const svg: <T extends keyof SVGElementTagNameMap>(tag: T) => <P extends Attributes>(attributes?: P | undefined) => (...children: Child[]) => SVGElementTagNameMap[T];
16
16
  declare const mathml: <T extends keyof MathMLElementEventMap>(tag: T) => <P extends Attributes>(attributes?: P | undefined) => (...children: Child[]) => MathMLElement;
17
17
  declare const xml: (tag: string) => <P extends Attributes>(attributes?: P) => (...children: Child[]) => HTMLElement;
18
- declare const list: <T>(render: (data: T, i: number) => Element) => (root: Element) => (next: T[]) => void;
18
+ declare const list: <T extends string | number>(render: (data: T, i: number) => Element) => (root: Element) => (next: T[]) => void;
19
19
 
20
20
  export { _default as default, env, list, mathml, svg, xml };
21
21
  export type { Attributes, Child, HTMLVoidElementTagName };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chronocide/hyper",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "types": "dist/hyper.d.ts",
6
6
  "exports": {