rasti 4.1.3-alpha.1 → 4.1.3

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
@@ -1,7 +1,7 @@
1
1
  <p align="center">
2
2
  <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.1.3-alpha.1/docs/logo-dark.svg">
4
- <img alt="Rasti.js" src="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.1.3-alpha.1/docs/logo.svg" height="120">
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.1.3/docs/logo-dark.svg">
4
+ <img alt="Rasti.js" src="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.1.3/docs/logo.svg" height="120">
5
5
  </picture>
6
6
  </p>
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rasti",
3
- "version": "4.1.3-alpha.1",
3
+ "version": "4.1.3",
4
4
  "description": "Modern MVC for building user interfaces",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",
@@ -1,7 +1,12 @@
1
1
  import View, { ViewOptions, Resolvable } from './View.js';
2
2
  import Model from './Model.js';
3
3
 
4
- export interface ComponentReservedOptions<S = any, M = any> extends ViewOptions<M, Component<any, S, M>> {
4
+ /** `P` types `this` in the hooks. It goes last so `ComponentReservedOptions<S, M>` keeps state and model first. */
5
+ export interface ComponentReservedOptions<
6
+ S = any,
7
+ M = any,
8
+ P = Record<string, any>,
9
+ > extends ViewOptions<M, Component<P, S, M>> {
5
10
  /**
6
11
  * A unique key to identify the component.
7
12
  * Components with keys are recycled when the same key is found in the previous render.
@@ -14,22 +19,22 @@ export interface ComponentReservedOptions<S = any, M = any> extends ViewOptions<
14
19
  */
15
20
  state?: S;
16
21
  /** Lifecycle hook called at the end of the constructor. */
17
- onCreate?: (this: Component<any, S, M>, ...args: any[]) => void;
22
+ onCreate?: (this: Component<P, S, M>, ...args: any[]) => void;
18
23
  /** Lifecycle hook called when `model`, `state` or `props` emits `change`. */
19
- onChange?: (this: Component<any, S, M>, ...args: any[]) => void;
24
+ onChange?: (this: Component<P, S, M>, ...args: any[]) => void;
20
25
  /** Lifecycle hook called after the first render (client only). */
21
- onHydrate?: (this: Component<any, S, M>) => void;
26
+ onHydrate?: (this: Component<P, S, M>) => void;
22
27
  /** Lifecycle hook called at the start of `recycle`, before any recycling happens. */
23
- onBeforeRecycle?: (this: Component<any, S, M>) => void;
28
+ onBeforeRecycle?: (this: Component<P, S, M>) => void;
24
29
  /** Lifecycle hook called after the component is recycled and props are updated. */
25
- onRecycle?: (this: Component<any, S, M>) => void;
30
+ onRecycle?: (this: Component<P, S, M>) => void;
26
31
  /** Lifecycle hook called at the start of `render` on update. */
27
- onBeforeUpdate?: (this: Component<any, S, M>) => void;
32
+ onBeforeUpdate?: (this: Component<P, S, M>) => void;
28
33
  /** Lifecycle hook called at the end of `render` on update. */
29
- onUpdate?: (this: Component<any, S, M>) => void;
34
+ onUpdate?: (this: Component<P, S, M>) => void;
30
35
  }
31
36
 
32
- export type ComponentOptions<P = Record<string, any>, S = any, M = any> = P & ComponentReservedOptions<S, M>;
37
+ export type ComponentOptions<P = Record<string, any>, S = any, M = any> = P & ComponentReservedOptions<S, M, P>;
33
38
 
34
39
  /** Marker type for strings that are safe to inject as HTML without sanitization. */
35
40
  export interface SafeHTML {
@@ -185,7 +190,10 @@ declare class Component<P = Record<string, any>, S = any, M = any> extends View<
185
190
  * - DOM event handlers via camelCased attributes (`onClick=${handler}`), delegated to the root.
186
191
  * - Returning a component instance (or array of them) adds it as a child.
187
192
  * - Use `<${Sub}>…</${Sub}>` syntax for child component tags.
188
- * - Called on a subclass, the new component extends it, so the template can use its methods.
193
+ * - Called on a subclass, the new component extends it and the result is that subclass,
194
+ * so the template can use its methods. `P`, `S` and `M` type the result when `create`
195
+ * is called on `Component`. A subclass does not take them: declare the arguments on
196
+ * the class (`class X extends Component<P, S, M>`) and call `X.create`.
189
197
  *
190
198
  * @example
191
199
  * const Button = Component.create`
@@ -200,11 +208,9 @@ declare class Component<P = Record<string, any>, S = any, M = any> extends View<
200
208
  strings: string | TemplateStringsArray | ((...args: any[]) => any),
201
209
  ...expressions: any[]
202
210
  ): T;
203
- /**
204
- * Creates a component from a template, typing its props, state and model explicitly.
205
- * See the overload above for the template syntax.
206
- */
211
+ /** Types props, state and model. Only `Component.create` takes these arguments; see above. */
207
212
  static create<P = Record<string, any>, S = any, M = any>(
213
+ this: typeof Component,
208
214
  strings: string | TemplateStringsArray | ((...args: any[]) => any),
209
215
  ...expressions: any[]
210
216
  ): typeof Component<P, S, M>;