@cascateer/core 2.4.6 → 2.4.8

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/slice.ts +146 -60
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.4.6",
3
+ "version": "2.4.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cascateer/core.git"
package/src/slice.ts CHANGED
@@ -15,69 +15,85 @@ import { StoreAdapter, StoreProvider } from "./store";
15
15
  import { TerminalAdapter, TerminalEffect, TerminalProvider } from "./terminal";
16
16
  import { Action } from "./types";
17
17
 
18
- interface SliceConfig<
18
+ interface SliceConfigStore<
19
19
  Data,
20
20
  StoreSignals extends Dictionary<ComputedSignal<any>>,
21
21
  StoreActions extends Dictionary<Action<any, any>>,
22
+ > extends UnaryFunction<
23
+ {
24
+ StoreProvider: {
25
+ new (): StoreProvider<Data>;
26
+ };
27
+ },
28
+ StoreAdapter<StoreSignals, StoreActions>
29
+ > {}
30
+
31
+ interface SliceConfigApi<
32
+ ApiEffects extends Dictionary<ApiEffect<any, any>>,
33
+ ApiActions extends Dictionary<Action<any, any>>,
34
+ > extends ApiAdapter<ApiEffects, ApiActions> {}
35
+
36
+ interface SliceConfigTerminal<
37
+ StoreSignals extends Dictionary<ComputedSignal<any>>,
38
+ StoreActions extends Dictionary<Action<any, any>>,
39
+ ApiEffects extends Dictionary<ApiEffect<any, any>>,
40
+ ApiActions extends Dictionary<Action<any, any>>,
41
+ TerminalEffects extends Dictionary<TerminalEffect<any, any>>,
42
+ TerminalActions extends Dictionary<Action<any, any>>,
43
+ > extends UnaryFunction<
44
+ {
45
+ TerminalProvider: {
46
+ new (): TerminalProvider<
47
+ StoreSignals,
48
+ StoreActions,
49
+ ApiEffects,
50
+ ApiActions
51
+ >;
52
+ };
53
+ },
54
+ TerminalAdapter<TerminalEffects, TerminalActions>
55
+ > {}
56
+
57
+ interface SliceConfigComponents<
58
+ StoreSignals extends Dictionary<ComputedSignal<any>>,
59
+ StoreActions extends Dictionary<Action<any, any>>,
22
60
  ApiEffects extends Dictionary<ApiEffect<any, any>>,
23
61
  ApiActions extends Dictionary<Action<any, any>>,
24
62
  TerminalEffects extends Dictionary<TerminalEffect<any, any>>,
25
63
  TerminalActions extends Dictionary<Action<any, any>>,
26
64
  Components extends Dictionary<ComponentConstructor<any>>,
27
- > {
28
- data: Data;
29
- store: UnaryFunction<
30
- {
31
- StoreProvider: {
32
- new (): StoreProvider<Data>;
33
- };
34
- },
35
- StoreAdapter<StoreSignals, StoreActions>
36
- >;
37
- api: ApiAdapter<ApiEffects, ApiActions>;
38
- terminal: UnaryFunction<
39
- {
40
- TerminalProvider: {
41
- new (): TerminalProvider<
42
- StoreSignals,
43
- StoreActions,
44
- ApiEffects,
45
- ApiActions
46
- >;
47
- };
48
- },
49
- TerminalAdapter<TerminalEffects, TerminalActions>
50
- >;
51
- components: UnaryFunction<
52
- {
53
- ComponentsProvider: {
54
- new (): ComponentsProvider<
55
- StoreSignals,
56
- StoreActions,
57
- ApiEffects,
58
- ApiActions,
59
- TerminalEffects,
60
- TerminalActions
61
- >;
62
- };
63
- },
64
- ComponentsAdapter<Components>
65
- >;
66
- render: UnaryFunction<
67
- {
68
- [K in keyof Components]: ReturnType<
69
- <
70
- Props extends Components[K] extends ComponentConstructor<infer Props>
71
- ? Props
72
- : never,
73
- >() => JSX.Component<Props>
65
+ > extends UnaryFunction<
66
+ {
67
+ ComponentsProvider: {
68
+ new (): ComponentsProvider<
69
+ StoreSignals,
70
+ StoreActions,
71
+ ApiEffects,
72
+ ApiActions,
73
+ TerminalEffects,
74
+ TerminalActions
74
75
  >;
75
- },
76
- JSX.Element
77
- >;
78
- }
76
+ };
77
+ },
78
+ ComponentsAdapter<Components>
79
+ > {}
80
+
81
+ interface SliceConfigTemplate<
82
+ Components extends Dictionary<ComponentConstructor<any>>,
83
+ > extends UnaryFunction<
84
+ {
85
+ [K in keyof Components]: ReturnType<
86
+ <
87
+ Props extends Components[K] extends ComponentConstructor<infer Props>
88
+ ? Props
89
+ : never,
90
+ >() => JSX.Component<Props>
91
+ >;
92
+ },
93
+ JSX.Element
94
+ > {}
79
95
 
80
- export const createSlice = <
96
+ interface SliceConfig<
81
97
  Data,
82
98
  StoreSignals extends Dictionary<ComputedSignal<any>>,
83
99
  StoreActions extends Dictionary<Action<any, any>>,
@@ -86,9 +102,19 @@ export const createSlice = <
86
102
  TerminalEffects extends Dictionary<TerminalEffect<any, any>>,
87
103
  TerminalActions extends Dictionary<Action<any, any>>,
88
104
  Components extends Dictionary<ComponentConstructor<any>>,
89
- >(
90
- config: SliceConfig<
91
- Data,
105
+ > {
106
+ data: Data;
107
+ store: SliceConfigStore<Data, StoreSignals, StoreActions>;
108
+ api: SliceConfigApi<ApiEffects, ApiActions>;
109
+ terminal: SliceConfigTerminal<
110
+ StoreSignals,
111
+ StoreActions,
112
+ ApiEffects,
113
+ ApiActions,
114
+ TerminalEffects,
115
+ TerminalActions
116
+ >;
117
+ components: SliceConfigComponents<
92
118
  StoreSignals,
93
119
  StoreActions,
94
120
  ApiEffects,
@@ -96,8 +122,68 @@ export const createSlice = <
96
122
  TerminalEffects,
97
123
  TerminalActions,
98
124
  Components
99
- >,
100
- ) => config;
125
+ >;
126
+ template: SliceConfigTemplate<Components>;
127
+ }
128
+
129
+ export const createSlice = () => ({
130
+ withData: <Data>(data: Data) => ({
131
+ withStore: <
132
+ StoreSignals extends Dictionary<ComputedSignal<any>>,
133
+ StoreActions extends Dictionary<Action<any, any>>,
134
+ >(
135
+ store: SliceConfigStore<Data, StoreSignals, StoreActions>,
136
+ ) => ({
137
+ withApi: <
138
+ ApiEffects extends Dictionary<ApiEffect<any, any>>,
139
+ ApiActions extends Dictionary<Action<any, any>>,
140
+ >(
141
+ api: SliceConfigApi<ApiEffects, ApiActions>,
142
+ ) => ({
143
+ withTerminal: <
144
+ TerminalEffects extends Dictionary<TerminalEffect<any, any>>,
145
+ TerminalActions extends Dictionary<Action<any, any>>,
146
+ >(
147
+ terminal: SliceConfigTerminal<
148
+ StoreSignals,
149
+ StoreActions,
150
+ ApiEffects,
151
+ ApiActions,
152
+ TerminalEffects,
153
+ TerminalActions
154
+ >,
155
+ ) => ({
156
+ withComponents: <
157
+ Components extends Dictionary<ComponentConstructor<any>>,
158
+ >(
159
+ components: SliceConfigComponents<
160
+ StoreSignals,
161
+ StoreActions,
162
+ ApiEffects,
163
+ ApiActions,
164
+ TerminalEffects,
165
+ TerminalActions,
166
+ Components
167
+ >,
168
+ ) => ({
169
+ withTemplate: (
170
+ template: SliceConfigTemplate<Components>,
171
+ ): SliceConfig<
172
+ Data,
173
+ StoreSignals,
174
+ StoreActions,
175
+ ApiEffects,
176
+ ApiActions,
177
+ TerminalEffects,
178
+ TerminalActions,
179
+ Components
180
+ > => ({ data, store, api, terminal, components, template }),
181
+ }),
182
+ }),
183
+ }),
184
+ }),
185
+ }),
186
+ });
101
187
 
102
188
  export class Slice<
103
189
  Data,
@@ -123,7 +209,7 @@ export class Slice<
123
209
  api,
124
210
  terminal,
125
211
  components,
126
- render,
212
+ template,
127
213
  }: SliceConfig<
128
214
  Data,
129
215
  StoreSignals,
@@ -166,7 +252,7 @@ export class Slice<
166
252
  map(
167
253
  (key) =>
168
254
  new (defineCustomElement(`${key}-slice`))(
169
- render(
255
+ template(
170
256
  mapValues(
171
257
  components({
172
258
  ComponentsProvider: ((context) =>