ballerina-core 1.0.2 → 1.0.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/main.ts +6 -1
- package/package.json +1 -1
- package/src/async/domains/mirroring/domains/collection/coroutines/synchronizers.ts +66 -9
- package/src/async/domains/mirroring/domains/singleton/coroutines/synchronizers.ts +35 -10
- package/src/forms/domains/launcher/coroutines/runner.ts +57 -0
- package/src/forms/domains/launcher/domains/merger/state.ts +9 -0
- package/src/forms/domains/launcher/state.ts +22 -0
- package/src/forms/domains/launcher/template.tsx +47 -0
- package/src/forms/domains/parser/coroutines/runner.ts +34 -0
- package/src/forms/domains/parser/domains/validator/state.ts +157 -46
- package/src/forms/domains/parser/state.tsx +71 -4
- package/src/forms/domains/parser/template.tsx +4 -0
- package/src/forms/domains/primitives/domains/boolean/state.ts +2 -2
- package/src/forms/domains/primitives/domains/boolean/template.tsx +4 -4
- package/src/forms/domains/primitives/domains/date/state.ts +1 -1
- package/src/forms/domains/primitives/domains/date/template.tsx +2 -2
- package/src/forms/domains/primitives/domains/enum/state.ts +1 -1
- package/src/forms/domains/primitives/domains/enum/template.tsx +3 -3
- package/src/forms/domains/primitives/domains/enum-multiselect/state.ts +1 -0
- package/src/forms/domains/primitives/domains/enum-multiselect/template.tsx +3 -3
- package/src/forms/domains/primitives/domains/number/state.ts +2 -1
- package/src/forms/domains/primitives/domains/number/template.tsx +3 -3
- package/src/forms/domains/primitives/domains/searchable-infinite-stream/state.ts +2 -1
- package/src/forms/domains/primitives/domains/searchable-infinite-stream/template.tsx +3 -3
- package/src/forms/domains/primitives/domains/searchable-infinite-stream-multiselect/state.ts +2 -1
- package/src/forms/domains/primitives/domains/searchable-infinite-stream-multiselect/template.tsx +3 -3
- package/src/forms/domains/primitives/domains/string/state.ts +1 -1
- package/src/forms/domains/primitives/domains/string/template.tsx +2 -2
- package/src/forms/domains/singleton/domains/mapping/state.ts +40 -34
- package/src/forms/domains/singleton/domains/mapping/template.tsx +4 -1
- package/src/forms/domains/singleton/state.ts +3 -2
- package/src/forms/domains/singleton/template.tsx +8 -2
package/main.ts
CHANGED
|
@@ -90,14 +90,19 @@ export * from "./src/forms/domains/primitives/domains/searchable-infinite-stream
|
|
|
90
90
|
export * from "./src/forms/domains/singleton/domains/mapping/state"
|
|
91
91
|
export * from "./src/forms/domains/singleton/domains/mapping/template"
|
|
92
92
|
export * from "./src/forms/domains/parser/state"
|
|
93
|
+
export * from "./src/forms/domains/parser/template"
|
|
94
|
+
export * from "./src/forms/domains/parser/coroutines/runner"
|
|
93
95
|
export * from "./src/forms/domains/parser/domains/validator/state"
|
|
94
|
-
export * from "./src/forms/domains/parser/domains/merger/state"
|
|
95
96
|
export * from "./src/forms/domains/launcher/domains/edit/state"
|
|
96
97
|
export * from "./src/forms/domains/launcher/domains/edit/template"
|
|
97
98
|
export * from "./src/forms/domains/launcher/domains/edit/coroutines/runner"
|
|
98
99
|
export * from "./src/forms/domains/launcher/domains/create/state"
|
|
99
100
|
export * from "./src/forms/domains/launcher/domains/create/template"
|
|
100
101
|
export * from "./src/forms/domains/launcher/domains/create/coroutines/runner"
|
|
102
|
+
export * from "./src/forms/domains/launcher/domains/merger/state"
|
|
103
|
+
export * from "./src/forms/domains/launcher/coroutines/runner"
|
|
104
|
+
export * from "./src/forms/domains/launcher/state"
|
|
105
|
+
export * from "./src/forms/domains/launcher/template"
|
|
101
106
|
|
|
102
107
|
// import { simpleUpdater, simpleUpdaterWithChildren } from "./src/fun/domains/updater/domains/simpleUpdater/state"
|
|
103
108
|
// import { Updater } from "./src/fun/domains/updater/state"
|
package/package.json
CHANGED
|
@@ -249,8 +249,22 @@ export const collectionEntityUpdater = <Collections, CollectionMutations, WholeC
|
|
|
249
249
|
Collection<Collections[k]>().Updaters.Template.entityValue(id, u)
|
|
250
250
|
));
|
|
251
251
|
|
|
252
|
+
export type CollectionMutationArgumentComparators<Collections, CollectionMutations> = {
|
|
253
|
+
[k in keyof Collections & keyof CollectionMutations]: {[_ in keyof CollectionMutations[k]]: MutationArgumentComparator<CollectionMutations[k][_]>};
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export type WholeCollectionMutationArgumentComparators<Collections, WholeCollectionMutations> = {
|
|
257
|
+
[k in keyof Collections & keyof WholeCollectionMutations]: {[_ in keyof WholeCollectionMutations[k]]: MutationArgumentComparator<WholeCollectionMutations[k][_]>};
|
|
258
|
+
};
|
|
259
|
+
|
|
252
260
|
export type InsertionPosition = { kind: "after", id: Guid } | { kind: "before", id: Guid } | { kind: "at the end" } | { kind: "at the beginning" }
|
|
253
261
|
|
|
262
|
+
export type ComparisonResult = ">" | "<" | "==";
|
|
263
|
+
|
|
264
|
+
export type MutationArgumentComparator<T> = BasicFun<[T, T], ComparisonResult>;
|
|
265
|
+
|
|
266
|
+
export const withTrivialComparator = <f, ma>(_: f): [f, MutationArgumentComparator<ma>] => [_, (_) => "=="];
|
|
267
|
+
|
|
254
268
|
export type SynchronizableCollectionEntity<Context, Collections, CollectionMutations, WholeCollectionMutations, SynchronizedEntities, k extends (keyof Collections) & (keyof CollectionMutations) & (keyof WholeCollectionMutations)> = {
|
|
255
269
|
entityName: k,
|
|
256
270
|
// default: BasicFun<void, CollectionEntity<Collections[k]>>,
|
|
@@ -265,10 +279,16 @@ export type SynchronizableCollectionEntity<Context, Collections, CollectionMutat
|
|
|
265
279
|
// reload: () =>
|
|
266
280
|
// Coroutine<Context & Synchronized<Unit, OrderedMap<Guid, CollectionEntity<Collections[k]>>>, Synchronized<Unit, OrderedMap<Guid, CollectionEntity<Collections[k]>>>, Unit>,
|
|
267
281
|
} & {
|
|
268
|
-
[_ in keyof (CollectionMutations[k])]:
|
|
282
|
+
[_ in keyof (CollectionMutations[k])]: [
|
|
283
|
+
BasicFun<CollectionMutations[k][_], Coroutine<Context & Synchronized<Value<Synchronized<Unit, Collections[k]>>, Unit>, Synchronized<Value<Synchronized<Unit, Collections[k]>>, Unit>, Unit>>,
|
|
284
|
+
MutationArgumentComparator<CollectionMutations[k][_]>,
|
|
285
|
+
]
|
|
269
286
|
} & {
|
|
270
287
|
wholeMutations:{
|
|
271
|
-
[_ in keyof (WholeCollectionMutations[k])]:
|
|
288
|
+
[_ in keyof (WholeCollectionMutations[k])]: [
|
|
289
|
+
BasicFun<WholeCollectionMutations[k][_], Coroutine<Context & Synchronized<Unit, OrderedMap<Guid, CollectionEntity<Collections[k]>>>, Synchronized<Unit, OrderedMap<Guid, CollectionEntity<Collections[k]>>>, Unit>>,
|
|
290
|
+
MutationArgumentComparator<WholeCollectionMutations[k][_]>
|
|
291
|
+
]
|
|
272
292
|
}
|
|
273
293
|
}
|
|
274
294
|
|
|
@@ -284,7 +304,9 @@ export const collectionSynchronizationContext = <Context, Collections, Collectio
|
|
|
284
304
|
CollectionDirtyCheckers<Collections, CollectionMutations, WholeCollectionMutations>,
|
|
285
305
|
CollectionDirtySetters<Context, Collections, CollectionMutations, WholeCollectionMutations, SynchronizedEntities>,
|
|
286
306
|
CollectionUpdaters<Collections, CollectionMutations, WholeCollectionMutations, SynchronizedEntities>,
|
|
287
|
-
SynchronizableEntityDescriptor<Context, Collections, CollectionMutations, WholeCollectionMutations, SynchronizedEntities
|
|
307
|
+
SynchronizableEntityDescriptor<Context, Collections, CollectionMutations, WholeCollectionMutations, SynchronizedEntities>,
|
|
308
|
+
CollectionMutationArgumentComparators<Collections, CollectionMutations>,
|
|
309
|
+
CollectionMutationArgumentComparators<Collections, WholeCollectionMutations>,
|
|
288
310
|
] => {
|
|
289
311
|
let synchronizers: CollectionSynchronizers<Context, Collections, CollectionMutations, WholeCollectionMutations> = {} as any
|
|
290
312
|
Object.keys(entityDescriptors).forEach(k_s => {
|
|
@@ -307,28 +329,63 @@ export const collectionSynchronizationContext = <Context, Collections, Collectio
|
|
|
307
329
|
(synchronizers[k] as any)["wholeMutations"][field] = (mutationArg:any) => (entityDescriptors[k]["wholeMutations"] as any)[field](mutationArg)
|
|
308
330
|
})
|
|
309
331
|
})
|
|
310
|
-
|
|
332
|
+
const loaders: CollectionLoaders<Context, Collections, CollectionMutations, WholeCollectionMutations, SynchronizedEntities> = {} as any
|
|
311
333
|
Object.keys(entityDescriptors).forEach(k_s => {
|
|
312
334
|
const k = k_s as (keyof Collections) & (keyof CollectionMutations) & (keyof WholeCollectionMutations)
|
|
313
335
|
loaders[k] = collectionEntityLoader<Context, Collections, CollectionMutations, WholeCollectionMutations, SynchronizedEntities>(synchronizers)(k, entityDescriptors[k].id, entityDescriptors[k].narrowing, entityDescriptors[k].widening, entityDescriptors[k].dependees)
|
|
314
336
|
})
|
|
315
|
-
|
|
337
|
+
const dirtyCheckers: CollectionDirtyCheckers<Collections, CollectionMutations, WholeCollectionMutations> = {} as any
|
|
316
338
|
Object.keys(entityDescriptors).forEach(k_s => {
|
|
317
339
|
const k = k_s as (keyof Collections) & (keyof CollectionMutations) & (keyof WholeCollectionMutations)
|
|
318
340
|
dirtyCheckers[k] = Fun(collectionCheckNotDirty<Collections, CollectionMutations, WholeCollectionMutations>())
|
|
319
341
|
})
|
|
320
|
-
|
|
342
|
+
const dirtySetters: CollectionDirtySetters<Context, Collections, CollectionMutations, WholeCollectionMutations, SynchronizedEntities> = {} as any
|
|
321
343
|
Object.keys(entityDescriptors).forEach(k_s => {
|
|
322
344
|
const k = k_s as (keyof Collections) & (keyof CollectionMutations) & (keyof WholeCollectionMutations)
|
|
323
345
|
dirtySetters[k] =
|
|
324
346
|
collectionDirtySetter<Context, Collections, CollectionMutations, WholeCollectionMutations, SynchronizedEntities>()
|
|
325
347
|
(k, entityDescriptors[k].narrowing, entityDescriptors[k].widening)
|
|
326
348
|
})
|
|
327
|
-
|
|
349
|
+
const updaters: CollectionUpdaters<Collections, CollectionMutations, WholeCollectionMutations, SynchronizedEntities> = {} as any
|
|
328
350
|
Object.keys(entityDescriptors).forEach(k_s => {
|
|
329
351
|
const k = k_s as (keyof Collections) & (keyof CollectionMutations) & (keyof WholeCollectionMutations)
|
|
330
352
|
updaters[k] = collectionEntityUpdater<Collections, CollectionMutations, WholeCollectionMutations, SynchronizedEntities>()(entityDescriptors[k].widening)
|
|
331
353
|
})
|
|
332
|
-
|
|
333
|
-
|
|
354
|
+
const mutationComparators: CollectionMutationArgumentComparators<Collections, CollectionMutations> = {} as any;
|
|
355
|
+
Object.keys(entityDescriptors).forEach((k_s) => {
|
|
356
|
+
const k = k_s as (keyof Collections) & (keyof CollectionMutations) & (keyof WholeCollectionMutations);
|
|
357
|
+
mutationComparators[k] = {} as any;
|
|
358
|
+
Object.keys(entityDescriptors[k]).forEach((field) => {
|
|
359
|
+
if (
|
|
360
|
+
field != "entityName" &&
|
|
361
|
+
field != "narrowing" &&
|
|
362
|
+
field != "widening" &&
|
|
363
|
+
field != "dependees" &&
|
|
364
|
+
field != "add" &&
|
|
365
|
+
field != "remove" &&
|
|
366
|
+
field != "default" &&
|
|
367
|
+
field != "reload"
|
|
368
|
+
)
|
|
369
|
+
(mutationComparators[k] as any)[field] = (entityDescriptors[k] as any)[field][1]
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
const wholeMutationComparators: WholeCollectionMutationArgumentComparators<Collections, WholeCollectionMutations> = {} as any;
|
|
373
|
+
Object.keys(entityDescriptors).forEach((k_s) => {
|
|
374
|
+
const k = k_s as (keyof Collections) & (keyof CollectionMutations) & (keyof WholeCollectionMutations);
|
|
375
|
+
wholeMutationComparators[k] = {} as any;
|
|
376
|
+
Object.keys(entityDescriptors[k]).forEach((field) => {
|
|
377
|
+
if (
|
|
378
|
+
field != "entityName" &&
|
|
379
|
+
field != "narrowing" &&
|
|
380
|
+
field != "widening" &&
|
|
381
|
+
field != "dependees" &&
|
|
382
|
+
field != "add" &&
|
|
383
|
+
field != "remove" &&
|
|
384
|
+
field != "default" &&
|
|
385
|
+
field != "reload"
|
|
386
|
+
)
|
|
387
|
+
(wholeMutationComparators[k] as any)[field] = (entityDescriptors[k] as any)[field][1];
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
return [loaders, dirtyCheckers, dirtySetters, updaters, entityDescriptors, mutationComparators, wholeMutationComparators]
|
|
334
391
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Unit, replaceWith, BasicUpdater, Updater, Value, AsyncState, unit } from "../../../../../../../main";
|
|
1
|
+
import { Unit, replaceWith, BasicUpdater, Updater, Value, AsyncState, unit, MutationArgumentComparator } from "../../../../../../../main";
|
|
2
2
|
import { CoTypedFactory } from "../../../../../../coroutines/builder";
|
|
3
3
|
import { Coroutine } from "../../../../../../coroutines/state";
|
|
4
4
|
import { Debounced, DirtyStatus } from "../../../../../../debounced/state";
|
|
@@ -35,6 +35,10 @@ export type SingletonLoaders<Context, Singletons, SingletonMutations, Synchroniz
|
|
|
35
35
|
Coroutine<Context & SynchronizedEntities, SynchronizedEntities, SynchronizationResult>;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
export type SingletonMutationArgumentComparators<Singletons, SingletonMutation> = {
|
|
39
|
+
[k in (keyof Singletons) & (keyof SingletonMutation)]: {[_ in keyof SingletonMutation[k]]: MutationArgumentComparator<SingletonMutation[k][_]>};
|
|
40
|
+
};
|
|
41
|
+
|
|
38
42
|
export const singletonEntityLoader = <Context, Singletons, SingletonMutations, SynchronizedEntities>(
|
|
39
43
|
synchronizers: SingletonSynchronizers<Context, Singletons, SingletonMutations>) => <k extends (keyof Singletons) & (keyof SingletonMutations)>(
|
|
40
44
|
k: k, narrowing_k: BasicFun<SynchronizedEntities, Singleton<Singletons[k]>>,
|
|
@@ -147,7 +151,10 @@ export type SynchronizableSingletonEntity<Context, Singletons, SingletonMutation
|
|
|
147
151
|
dependees: Array<Coroutine<Context & SynchronizedEntities, SynchronizedEntities, SynchronizationResult>>,
|
|
148
152
|
// reload: Coroutine<Context & Synchronized<Unit, Singletons[k]>, Synchronized<Unit, Singletons[k]>, Unit>,
|
|
149
153
|
} & {
|
|
150
|
-
[_ in keyof (SingletonMutations[k])]:
|
|
154
|
+
[_ in keyof (SingletonMutations[k])]: [
|
|
155
|
+
BasicFun<SingletonMutations[k][_], Coroutine<Context & Synchronized<Value<Synchronized<Unit, Singletons[k]>>, Unit>, Synchronized<Value<Synchronized<Unit, Singletons[k]>>, Unit>, Unit>>,
|
|
156
|
+
MutationArgumentComparator<SingletonMutations[k][_]>
|
|
157
|
+
]
|
|
151
158
|
}
|
|
152
159
|
|
|
153
160
|
export type SynchronizableEntityDescriptors<Context, Singletons, SingletonMutations, SynchronizedEntities> = {
|
|
@@ -163,9 +170,10 @@ export const singletonSynchronizationContext = <Context, Singletons, SingletonMu
|
|
|
163
170
|
SingletonDirtyCheckers<Singletons, SingletonMutations>,
|
|
164
171
|
SingletonDirtySetters<Context, Singletons, SingletonMutations, SynchronizedEntities>,
|
|
165
172
|
SingletonUpdaters<Singletons, SingletonMutations, SynchronizedEntities>,
|
|
166
|
-
SynchronizableEntityDescriptors<Context, Singletons, SingletonMutations, SynchronizedEntities
|
|
173
|
+
SynchronizableEntityDescriptors<Context, Singletons, SingletonMutations, SynchronizedEntities>,
|
|
174
|
+
SingletonMutationArgumentComparators<Singletons, SingletonMutations>,
|
|
167
175
|
] => {
|
|
168
|
-
|
|
176
|
+
const synchronizers: SingletonSynchronizers<Context, Singletons, SingletonMutations> = {} as any
|
|
169
177
|
Object.keys(entityDescriptors).forEach(k_s => {
|
|
170
178
|
const k = k_s as (keyof Singletons) & (keyof SingletonMutations)
|
|
171
179
|
|
|
@@ -176,7 +184,7 @@ export const singletonSynchronizationContext = <Context, Singletons, SingletonMu
|
|
|
176
184
|
(synchronizers[k] as any)[field] = (mutationArg:any) => insideEntitySynchronizedAndDebounced((entityDescriptors[k] as any)[field](mutationArg)) as any
|
|
177
185
|
})
|
|
178
186
|
})
|
|
179
|
-
|
|
187
|
+
const loaders: SingletonLoaders<Context, Singletons, SingletonMutations, SynchronizedEntities> = {} as any
|
|
180
188
|
Object.keys(entityDescriptors).forEach(k_s => {
|
|
181
189
|
const k = k_s as (keyof Singletons) & (keyof SingletonMutations)
|
|
182
190
|
loaders[k] = singletonEntityLoader<Context, Singletons, SingletonMutations, SynchronizedEntities>(synchronizers)(k, entityDescriptors[k].narrowing, entityDescriptors[k].widening, entityDescriptors[k].dependees)
|
|
@@ -193,24 +201,41 @@ export const singletonSynchronizationContext = <Context, Singletons, SingletonMu
|
|
|
193
201
|
// reloaders[k] = singletonEntityReloader<Context, Singletons, SingletonMutations, SynchronizedEntities>(reloadSynchronizers)(k, entityDescriptors[k].narrowing, entityDescriptors[k].widening, entityDescriptors[k].dependees)
|
|
194
202
|
// })
|
|
195
203
|
|
|
196
|
-
|
|
204
|
+
const dirtyCheckers: SingletonDirtyCheckers<Singletons, SingletonMutations> = {} as any
|
|
197
205
|
Object.keys(entityDescriptors).forEach(k_s => {
|
|
198
206
|
const k = k_s as (keyof Singletons) & (keyof SingletonMutations)
|
|
199
207
|
dirtyCheckers[k] = Fun(singletonCheckNotDirty<Singletons, SingletonMutations>())
|
|
200
208
|
})
|
|
201
|
-
|
|
209
|
+
const dirtySetters: SingletonDirtySetters<Context, Singletons, SingletonMutations, SynchronizedEntities> = {} as any
|
|
202
210
|
Object.keys(entityDescriptors).forEach(k_s => {
|
|
203
211
|
const k = k_s as (keyof Singletons) & (keyof SingletonMutations)
|
|
204
212
|
dirtySetters[k] = singletonDirtySetter<Context, Singletons, SingletonMutations, SynchronizedEntities>()(
|
|
205
213
|
k, entityDescriptors[k].narrowing, entityDescriptors[k].widening
|
|
206
214
|
)
|
|
207
215
|
})
|
|
208
|
-
|
|
216
|
+
const updaters: SingletonUpdaters<Singletons, SingletonMutations, SynchronizedEntities> = {} as any
|
|
209
217
|
Object.keys(entityDescriptors).forEach(k_s => {
|
|
210
218
|
const k = k_s as (keyof Singletons) & (keyof SingletonMutations)
|
|
211
219
|
updaters[k] = singletonEntityUpdater<Singletons, SingletonMutations, SynchronizedEntities>()(entityDescriptors[k].widening)
|
|
212
220
|
})
|
|
213
|
-
|
|
214
|
-
|
|
221
|
+
const mutationComparators: SingletonMutationArgumentComparators<Singletons, SingletonMutations> = {} as any;
|
|
222
|
+
Object.keys(entityDescriptors).forEach((k_s) => {
|
|
223
|
+
const k = k_s as (keyof Singletons) & (keyof SingletonMutations)
|
|
224
|
+
mutationComparators[k] = {} as any;
|
|
225
|
+
Object.keys(entityDescriptors[k]).forEach((field) => {
|
|
226
|
+
if (
|
|
227
|
+
field != "entityName" &&
|
|
228
|
+
field != "narrowing" &&
|
|
229
|
+
field != "widening" &&
|
|
230
|
+
field != "dependees" &&
|
|
231
|
+
field != "add" &&
|
|
232
|
+
field != "remove" &&
|
|
233
|
+
field != "default" &&
|
|
234
|
+
field != "reload"
|
|
235
|
+
)
|
|
236
|
+
(mutationComparators[k] as any)[field] = (entityDescriptors[k] as any)[field][1];
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
return [loaders, /*reloaders,*/ dirtyCheckers, dirtySetters, updaters, entityDescriptors, mutationComparators]
|
|
215
240
|
}
|
|
216
241
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FormRunnerErrorsTemplate, id, replaceWith, Sum } from "../../../../../main"
|
|
2
|
+
import { AsyncState } from "../../../../async/state"
|
|
3
|
+
import { CoTypedFactory } from "../../../../coroutines/builder"
|
|
4
|
+
import { FormRunnerContext, FormRunnerForeignMutationsExpected, FormRunnerState } from "../state"
|
|
5
|
+
|
|
6
|
+
export const FormRunnerLoader = () => {
|
|
7
|
+
const Co = CoTypedFactory<FormRunnerContext, FormRunnerState>()
|
|
8
|
+
|
|
9
|
+
// const MaybePersonFromConfigForm = parsedFormsConfig.kind == "l" ?
|
|
10
|
+
// parsedFormsConfig.value.mappings.get("person-from-config") ?? undefined : undefined
|
|
11
|
+
// const PersonFromConfigForm =
|
|
12
|
+
// MaybePersonFromConfigForm != undefined ? MaybePersonFromConfigForm<any, any, any, any>()
|
|
13
|
+
// : PersonShowFormSetupErrors(validatedFormsConfig, parsedFormsConfig)
|
|
14
|
+
return Co.Template<FormRunnerForeignMutationsExpected>(
|
|
15
|
+
Co.GetState().then(current =>
|
|
16
|
+
!AsyncState.Operations.hasValue(current.formsConfig.sync) ?
|
|
17
|
+
Co.Wait(0)
|
|
18
|
+
: Co.UpdateState(_ => {
|
|
19
|
+
if (!AsyncState.Operations.hasValue(current.formsConfig.sync)) return id
|
|
20
|
+
if (current.formsConfig.sync.value.kind == "r")
|
|
21
|
+
return FormRunnerState.Updaters.form(
|
|
22
|
+
replaceWith(
|
|
23
|
+
Sum.Default.left(
|
|
24
|
+
FormRunnerErrorsTemplate(current.formsConfig.sync.value)
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
const mappedForm = current.formsConfig.sync.value.value.mappings.get(current.formName)
|
|
29
|
+
if (mappedForm == undefined)
|
|
30
|
+
return FormRunnerState.Updaters.form(
|
|
31
|
+
replaceWith(
|
|
32
|
+
Sum.Default.left(
|
|
33
|
+
FormRunnerErrorsTemplate(Sum.Default.right([`Cannot find form '${current.formName}'`]))
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
const instantiatedMappedForm = mappedForm()
|
|
38
|
+
return FormRunnerState.Updaters.form(
|
|
39
|
+
replaceWith(
|
|
40
|
+
Sum.Default.left({
|
|
41
|
+
form:instantiatedMappedForm.form,
|
|
42
|
+
formState:instantiatedMappedForm.initialState,
|
|
43
|
+
mapping:instantiatedMappedForm.mapping
|
|
44
|
+
})
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
})
|
|
48
|
+
),
|
|
49
|
+
{
|
|
50
|
+
interval: 15,
|
|
51
|
+
runFilter: props =>
|
|
52
|
+
AsyncState.Operations.hasValue(props.context.formsConfig.sync) &&
|
|
53
|
+
props.context.form.kind == "r"
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Mapping, simpleUpdater, Sum } from "../../../../main"
|
|
2
|
+
import { FormsParserState } from "../parser/state"
|
|
3
|
+
import { OnChange } from "../singleton/state"
|
|
4
|
+
|
|
5
|
+
export type FormRunnerContext = {
|
|
6
|
+
value:any
|
|
7
|
+
extraContext:any
|
|
8
|
+
viewWrappers:any
|
|
9
|
+
formName:string
|
|
10
|
+
} & FormsParserState
|
|
11
|
+
export type FormRunnerState = {
|
|
12
|
+
form:Sum<{ form:any, formState:any, mapping:Mapping<any,any> }, "not initialized">
|
|
13
|
+
}
|
|
14
|
+
export type FormRunnerForeignMutationsExpected = { onChange:OnChange<any> }
|
|
15
|
+
export const FormRunnerState = {
|
|
16
|
+
Default:():FormRunnerState => ({
|
|
17
|
+
form:Sum.Default.right("not initialized"),
|
|
18
|
+
}),
|
|
19
|
+
Updaters:{
|
|
20
|
+
...simpleUpdater<FormRunnerState>()("form"),
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { List } from "immutable"
|
|
2
|
+
import { BasicUpdater, FormRunnerContext, FormRunnerForeignMutationsExpected, FormRunnerLoader, FormRunnerState, Mapping, Sum, unit } from "../../../../main"
|
|
3
|
+
import { Template } from "../../../template/state"
|
|
4
|
+
import { FormParsingResult } from "../parser/state"
|
|
5
|
+
|
|
6
|
+
export const FormRunnerErrorsTemplate = (parsedFormsConfig: FormParsingResult) => ({
|
|
7
|
+
form: Template.Default((props: any) =>
|
|
8
|
+
<>
|
|
9
|
+
{parsedFormsConfig.kind == "r" && JSON.stringify(parsedFormsConfig.value)}
|
|
10
|
+
</>),
|
|
11
|
+
formState: unit,
|
|
12
|
+
mapping: Mapping.Default.fromPaths(unit)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export const FormRunnerTemplate =
|
|
17
|
+
Template.Default<FormRunnerContext & FormRunnerState, FormRunnerState, FormRunnerForeignMutationsExpected>(props =>
|
|
18
|
+
props.context.form.kind == "r" ? <></> :
|
|
19
|
+
<>
|
|
20
|
+
<props.context.form.value.form
|
|
21
|
+
context={{
|
|
22
|
+
...props.context.form.value.formState,
|
|
23
|
+
value: props.context.value,
|
|
24
|
+
formState: props.context.form.value.formState,
|
|
25
|
+
extraContext: {
|
|
26
|
+
...props.context.extraContext,
|
|
27
|
+
rootValue: props.context.form.value.mapping.from(props.context.value),
|
|
28
|
+
}
|
|
29
|
+
}}
|
|
30
|
+
setState={(_:BasicUpdater<any>) => props.setState(
|
|
31
|
+
FormRunnerState.Updaters.form(
|
|
32
|
+
Sum.Updaters.left(
|
|
33
|
+
current => ({ ...current, formState: _(current.formState) })
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
)}
|
|
37
|
+
view={props.context.viewWrappers as any}
|
|
38
|
+
foreignMutations={{
|
|
39
|
+
onChange: (_:BasicUpdater<any>, _path:List<string>) => {
|
|
40
|
+
props.foreignMutations.onChange(_, _path)
|
|
41
|
+
}
|
|
42
|
+
}}
|
|
43
|
+
/>
|
|
44
|
+
|
|
45
|
+
</>).any([
|
|
46
|
+
FormRunnerLoader()
|
|
47
|
+
])
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AsyncState, FormsConfig, Sum, Synchronize, Unit } from "../../../../../main"
|
|
2
|
+
import { CoTypedFactory } from "../../../../coroutines/builder"
|
|
3
|
+
import { builtInsFromFieldViews, FormParsingResult, FormsParserContext, FormsParserState, parseForms } from "../state"
|
|
4
|
+
|
|
5
|
+
export const LoadValidateAndParseFormsConfig = () => {
|
|
6
|
+
const Co = CoTypedFactory<FormsParserContext, FormsParserState>()
|
|
7
|
+
|
|
8
|
+
return Co.Template<Unit>(
|
|
9
|
+
Co.GetState().then(current =>
|
|
10
|
+
Synchronize<Unit, FormParsingResult>(async() => {
|
|
11
|
+
const formsConfig = await current.getFormsConfig()
|
|
12
|
+
const builtIns = builtInsFromFieldViews(current.fieldViews)
|
|
13
|
+
const validationResult = FormsConfig.Default.validateAndParseAPIResponse(builtIns)(formsConfig)
|
|
14
|
+
if (validationResult.kind == "r")
|
|
15
|
+
return Sum.Default.right(validationResult.value)
|
|
16
|
+
return parseForms(
|
|
17
|
+
current.containerFormView,
|
|
18
|
+
current.fieldViews,
|
|
19
|
+
current.infiniteStreamSources,
|
|
20
|
+
current.enumOptionsSources,
|
|
21
|
+
current.entityApis,
|
|
22
|
+
current.leafPredicates)(validationResult.value)
|
|
23
|
+
}, _ => "transient failure", 5, 50)
|
|
24
|
+
.embed(
|
|
25
|
+
_ => _.formsConfig,
|
|
26
|
+
FormsParserState.Updaters.formsConfig
|
|
27
|
+
)
|
|
28
|
+
),
|
|
29
|
+
{
|
|
30
|
+
interval:15,
|
|
31
|
+
runFilter:props => !AsyncState.Operations.hasValue(props.context.formsConfig.sync)
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
}
|