@cascateer/core 2.4.8 → 2.4.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.4.8",
3
+ "version": "2.4.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cascateer/core.git"
package/src/component.ts CHANGED
@@ -10,8 +10,8 @@ import { asStoreEffects, StoreAdapter, StoreEffects } from "./store";
10
10
  import { TerminalAdapter, TerminalEffect } from "./terminal";
11
11
  import { Action, Effect } from "./types";
12
12
 
13
- export class ComponentConstructor<Props extends JSX.Props> {
14
- constructor(public predicate: UnaryFunction<string, JSX.Component<Props>>) {}
13
+ export interface ComponentConstructor<Props extends JSX.Props> {
14
+ (key: string): JSX.Component<Props>;
15
15
  }
16
16
 
17
17
  export function createComponent(customElement?: string) {
@@ -23,33 +23,49 @@ export function createComponent(customElement?: string) {
23
23
  >(
24
24
  constructor: (
25
25
  ctx: Context,
26
- ...classNamesList: { -readonly [K in keyof Styles]: Awaited<Styles[K]> }
26
+ ...cn: { -readonly [K in keyof Styles]: Awaited<Styles[K]> }
27
27
  ) => JSX.Component<Props>,
28
28
  ) =>
29
- class extends ComponentConstructor<Props> {
30
- constructor(ctx: Context) {
31
- super(
32
- (key) => (props) =>
33
- createFragment({
34
- children: defer(() =>
35
- Promise.all(styles).then((cssModules) =>
36
- cssStyleSheets(cssModules).then((cssStyleSheets) => {
37
- const element = constructor(ctx, ...cssModules)(props);
29
+ (ctx: Context): ComponentConstructor<Props> =>
30
+ (key) =>
31
+ (props) =>
32
+ createFragment({
33
+ children: defer(() =>
34
+ Promise.all(styles).then((cssModules) =>
35
+ cssStyleSheets(cssModules).then((cssStyleSheets) => {
36
+ const element = constructor(ctx, ...cssModules)(props);
38
37
 
39
- return customElement != null
40
- ? new (defineCustomElement(
41
- `${key}-${kebabCase(customElement)}`,
42
- ))(element, cssStyleSheets)
43
- : createFragment({
44
- children: element,
45
- }); /* TODO omit cssModules (whole workflow) */
46
- }),
47
- ),
48
- ).pipe(share()),
49
- }),
50
- );
51
- }
52
- };
38
+ return customElement != null
39
+ ? new (defineCustomElement(
40
+ `${key}-${kebabCase(customElement)}`,
41
+ ))(element, cssStyleSheets)
42
+ : createFragment({
43
+ children: element,
44
+ }); /* TODO omit cssModules (whole workflow) */
45
+ }),
46
+ ),
47
+ ).pipe(share()),
48
+ });
49
+
50
+ return {
51
+ withStyles: <Styles extends Promise<unknown>[]>(...styles: Styles) => ({
52
+ withTemplate: withTemplate(...styles),
53
+ }),
54
+ withTemplate: withTemplate(),
55
+ };
56
+ }
57
+
58
+ export function createStandaloneComponent(customElement?: string) {
59
+ const withTemplate =
60
+ <Styles extends Promise<unknown>[]>(...styles: Styles) =>
61
+ <Props extends JSX.Props>(
62
+ constructor: (
63
+ ...cn: { -readonly [K in keyof Styles]: Awaited<Styles[K]> }
64
+ ) => JSX.Component<Props>,
65
+ ): ComponentConstructor<Props> =>
66
+ createComponent(customElement)
67
+ .withStyles(...styles)
68
+ .withTemplate<{}, Props>((_, ...cn) => constructor(...cn))({});
53
69
 
54
70
  return {
55
71
  withStyles: <Styles extends Promise<unknown>[]>(...styles: Styles) => ({
package/src/slice.ts CHANGED
@@ -269,8 +269,7 @@ export class Slice<
269
269
  }
270
270
  })({ store: this.store, api, terminal: this.terminal }),
271
271
  }).components,
272
- (componentConstructor) =>
273
- componentConstructor.predicate(key),
272
+ (componentConstructor) => componentConstructor(key),
274
273
  ),
275
274
  ),
276
275
  ),