ballerina-core 1.0.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.
Files changed (118) hide show
  1. package/main.ts +149 -0
  2. package/package.json +20 -0
  3. package/src/apiResultStatus/state.ts +7 -0
  4. package/src/async/domains/mirroring/domains/collection/coroutines/synchronizers.ts +334 -0
  5. package/src/async/domains/mirroring/domains/collection/state.ts +137 -0
  6. package/src/async/domains/mirroring/domains/entity/domains/loaded-collection/state.ts +24 -0
  7. package/src/async/domains/mirroring/domains/entity/domains/loaded-collection-entity/state.ts +27 -0
  8. package/src/async/domains/mirroring/domains/entity/domains/loaded-entities/state.ts +12 -0
  9. package/src/async/domains/mirroring/domains/entity/domains/loaded-entity/state.ts +29 -0
  10. package/src/async/domains/mirroring/domains/entity/state.ts +22 -0
  11. package/src/async/domains/mirroring/domains/singleton/coroutines/synchronizers.ts +216 -0
  12. package/src/async/domains/mirroring/domains/singleton/state.ts +57 -0
  13. package/src/async/domains/mirroring/domains/synchronization-result/state.ts +2 -0
  14. package/src/async/domains/mirroring/domains/synchronized-entities/state.ts +23 -0
  15. package/src/async/domains/promise/state.ts +13 -0
  16. package/src/async/domains/synchronized/coroutines/synchronize.ts +62 -0
  17. package/src/async/domains/synchronized/state.ts +20 -0
  18. package/src/async/state.ts +144 -0
  19. package/src/baseEntity/domains/identifiable/state.ts +29 -0
  20. package/src/collections/domains/array/state.ts +16 -0
  21. package/src/collections/domains/immutable/domains/list/state.ts +20 -0
  22. package/src/collections/domains/immutable/domains/map/state.ts +33 -0
  23. package/src/collections/domains/immutable/domains/orderedMap/state.ts +117 -0
  24. package/src/collections/domains/immutable/domains/ordereredSet/state.ts +19 -0
  25. package/src/collections/domains/immutable/domains/set/state.ts +15 -0
  26. package/src/collections/domains/maybe/state.ts +20 -0
  27. package/src/collections/domains/product/state.ts +47 -0
  28. package/src/collections/domains/sum/state.ts +82 -0
  29. package/src/coroutines/builder.tsx +66 -0
  30. package/src/coroutines/state.ts +574 -0
  31. package/src/coroutines/template.tsx +119 -0
  32. package/src/debounced/coroutines/debounce.ts +118 -0
  33. package/src/debounced/state.ts +61 -0
  34. package/src/diagnostics/domains/message-box/state.ts +4 -0
  35. package/src/foreignMutations/state.ts +4 -0
  36. package/src/forms/domains/attachments/views/attachments-view.tsx +22 -0
  37. package/src/forms/domains/collection/domains/reference/state.ts +18 -0
  38. package/src/forms/domains/collection/domains/selection/state.ts +5 -0
  39. package/src/forms/domains/launcher/domains/create/coroutines/runner.ts +60 -0
  40. package/src/forms/domains/launcher/domains/create/state.ts +71 -0
  41. package/src/forms/domains/launcher/domains/create/template.tsx +66 -0
  42. package/src/forms/domains/launcher/domains/edit/coroutines/runner.ts +47 -0
  43. package/src/forms/domains/launcher/domains/edit/state.ts +55 -0
  44. package/src/forms/domains/launcher/domains/edit/template.tsx +39 -0
  45. package/src/forms/domains/parser/domains/validator/state.ts +423 -0
  46. package/src/forms/domains/parser/state.tsx +311 -0
  47. package/src/forms/domains/primitives/domains/boolean/state.ts +13 -0
  48. package/src/forms/domains/primitives/domains/boolean/template.tsx +24 -0
  49. package/src/forms/domains/primitives/domains/date/state.ts +23 -0
  50. package/src/forms/domains/primitives/domains/date/template.tsx +31 -0
  51. package/src/forms/domains/primitives/domains/enum/state.ts +27 -0
  52. package/src/forms/domains/primitives/domains/enum/template.tsx +52 -0
  53. package/src/forms/domains/primitives/domains/enum-multiselect/state.ts +18 -0
  54. package/src/forms/domains/primitives/domains/enum-multiselect/template.tsx +56 -0
  55. package/src/forms/domains/primitives/domains/number/state.ts +8 -0
  56. package/src/forms/domains/primitives/domains/number/template.tsx +26 -0
  57. package/src/forms/domains/primitives/domains/searchable-infinite-stream/state.ts +55 -0
  58. package/src/forms/domains/primitives/domains/searchable-infinite-stream/template.tsx +114 -0
  59. package/src/forms/domains/primitives/domains/searchable-infinite-stream-multiselect/state.ts +27 -0
  60. package/src/forms/domains/primitives/domains/searchable-infinite-stream-multiselect/template.tsx +119 -0
  61. package/src/forms/domains/primitives/domains/string/state.ts +12 -0
  62. package/src/forms/domains/primitives/domains/string/template.tsx +24 -0
  63. package/src/forms/domains/singleton/domains/descriptors/entity/state.ts +9 -0
  64. package/src/forms/domains/singleton/domains/descriptors/field/domains/base/state.ts +5 -0
  65. package/src/forms/domains/singleton/domains/descriptors/field/domains/boolean/state.ts +6 -0
  66. package/src/forms/domains/singleton/domains/descriptors/field/domains/custom/state.ts +21 -0
  67. package/src/forms/domains/singleton/domains/descriptors/field/domains/date/state.ts +6 -0
  68. package/src/forms/domains/singleton/domains/descriptors/field/domains/enum/state.ts +7 -0
  69. package/src/forms/domains/singleton/domains/descriptors/field/domains/infinite-enum/state.ts +8 -0
  70. package/src/forms/domains/singleton/domains/descriptors/field/domains/number/state.ts +7 -0
  71. package/src/forms/domains/singleton/domains/descriptors/field/domains/string/state.ts +7 -0
  72. package/src/forms/domains/singleton/domains/descriptors/field/state.ts +16 -0
  73. package/src/forms/domains/singleton/domains/descriptors/form/state.ts +13 -0
  74. package/src/forms/domains/singleton/domains/form-label/state.ts +2 -0
  75. package/src/forms/domains/singleton/state.ts +87 -0
  76. package/src/forms/domains/singleton/template.tsx +92 -0
  77. package/src/forms/domains/singleton/views/field-views.ts +23 -0
  78. package/src/forms/domains/singleton/views/simple-inputs/base.ts +5 -0
  79. package/src/forms/domains/singleton/views/simple-inputs/boolean.tsx +4 -0
  80. package/src/forms/domains/singleton/views/simple-inputs/date.tsx +4 -0
  81. package/src/forms/domains/singleton/views/simple-inputs/number.tsx +4 -0
  82. package/src/forms/domains/singleton/views/simple-inputs/string.tsx +4 -0
  83. package/src/fun/domains/curry/state.ts +6 -0
  84. package/src/fun/domains/id/state.ts +2 -0
  85. package/src/fun/domains/predicate/domains/bool-expr.ts +98 -0
  86. package/src/fun/domains/predicate/state.ts +29 -0
  87. package/src/fun/domains/simpleCallback/state.ts +3 -0
  88. package/src/fun/domains/uncurry/state.ts +5 -0
  89. package/src/fun/domains/unit/state.ts +3 -0
  90. package/src/fun/domains/updater/domains/caseUpdater/state.ts +44 -0
  91. package/src/fun/domains/updater/domains/mapUpdater/state.ts +36 -0
  92. package/src/fun/domains/updater/domains/maybeUpdater/state.ts +45 -0
  93. package/src/fun/domains/updater/domains/orderedMapUpdater/state.ts +26 -0
  94. package/src/fun/domains/updater/domains/orderedSetUpdater/state.ts +23 -0
  95. package/src/fun/domains/updater/domains/replaceWith/state.ts +3 -0
  96. package/src/fun/domains/updater/domains/simpleUpdater/domains/baseSimpleUpdater/state.ts +18 -0
  97. package/src/fun/domains/updater/domains/simpleUpdater/state.ts +72 -0
  98. package/src/fun/domains/updater/state.ts +86 -0
  99. package/src/fun/state.ts +33 -0
  100. package/src/infinite-data-stream/coroutines/builder.ts +8 -0
  101. package/src/infinite-data-stream/coroutines/infiniteLoader.ts +51 -0
  102. package/src/infinite-data-stream/coroutines/runner.ts +12 -0
  103. package/src/infinite-data-stream/state.ts +175 -0
  104. package/src/infinite-data-stream/template.tsx +16 -0
  105. package/src/math/domains/DOMRect/state.ts +12 -0
  106. package/src/math/domains/number/state.ts +9 -0
  107. package/src/math/domains/rect/state.ts +22 -0
  108. package/src/math/domains/rgba/state.ts +87 -0
  109. package/src/math/domains/size2/state.ts +14 -0
  110. package/src/math/domains/vector2/state.ts +16 -0
  111. package/src/queue/state.ts +42 -0
  112. package/src/state/domains/repository/state.ts +14 -0
  113. package/src/template/state.tsx +198 -0
  114. package/src/validation/state.ts +2 -0
  115. package/src/value/domains/mutable-value/state.ts +13 -0
  116. package/src/value/state.ts +12 -0
  117. package/src/visibility/state.ts +3 -0
  118. package/tsconfig.json +22 -0
@@ -0,0 +1,86 @@
1
+ import { BasicFun, Fun } from "../../state";
2
+
3
+ export type BasicUpdater<e> = BasicFun<e, e>;
4
+
5
+ export type Updater<e> = BasicUpdater<e> & {
6
+ fun: Fun<e, e>;
7
+ then(other: BasicUpdater<e>): Updater<e>;
8
+ thenMany(others: Array<BasicUpdater<e>>): Updater<e>;
9
+ };
10
+
11
+ export const Updater = <e>(u: BasicUpdater<e>): Updater<e> => {
12
+ return Object.assign(u, {
13
+ fun: Fun(u),
14
+ then: function (this: Updater<e>, other: BasicUpdater<e>): Updater<e> {
15
+ return Updater<e>(_ => other(this(_)));
16
+ },
17
+ thenMany: function (this: Updater<e>, others: Array<BasicUpdater<e>>): Updater<e> {
18
+ return Updater<e>(others.map(_ => Updater(_)).reduce((f, g) => f.then(g), this));
19
+ }
20
+ });
21
+ }
22
+
23
+ /*export const Updater = Object.assign(<e>(_: BasicUpdater<e>): Updater<e> => {
24
+ const u = _ as Updater<e>;
25
+ u.fun = Fun(u);
26
+ u.thenMany = function (this: Updater<e>, others: Array<BasicUpdater<e>>): Updater<e> {
27
+ return Updater<e>(others.map(_ => Updater(_)).reduce((f, g) => f.then(g), this));
28
+ };
29
+ u.then = function (this: Updater<e>, other: BasicUpdater<e>): Updater<e> {
30
+ return Updater<e>(_ => other(this(_)));
31
+ };
32
+ return u;
33
+ }, {
34
+ withState:<e>(_: BasicFun<e,BasicUpdater<e>>) : Updater<e> =>
35
+ Updater(e => _(e)(e))
36
+ });
37
+ */
38
+
39
+ /*
40
+ // little testing playground and microsample: please do not remove
41
+ import { simpleUpdater, simpleUpdaterWithChildren } from "./domains/simpleUpdater/state";
42
+ type City = { name: string, population: number }
43
+ const City = {
44
+ Default: (): City => ({
45
+ name: "Mirano", population: 25000
46
+ }),
47
+ Updaters: {
48
+ Core: {
49
+ ...simpleUpdater<City>()("name"),
50
+ ...simpleUpdater<City>()("population"),
51
+ }
52
+ }
53
+ }
54
+ type Address = { street: string, number: number, city: City}
55
+ const Address = {
56
+ Default: (): Address => ({
57
+ street: "via Don Minzoni", number: 20, city: City.Default()
58
+ }),
59
+ Updaters: {
60
+ Core: {
61
+ ...simpleUpdater<Address>()("street"),
62
+ ...simpleUpdater<Address>()("number"),
63
+ ...simpleUpdaterWithChildren<Address>()(City.Updaters)("city"),
64
+ }
65
+ }
66
+ }
67
+ type Person = { name: string, surname: string, address: Address }
68
+ const Person = {
69
+ Default: (): Person => ({
70
+ name: "John", surname: "Doe", address: Address.Default()
71
+ }),
72
+ Updaters: {
73
+ Core: {
74
+ ...simpleUpdater<Person>()("name"),
75
+ ...simpleUpdater<Person>()("surname"),
76
+ ...simpleUpdaterWithChildren<Person>()(Address.Updaters)("address"),
77
+ }
78
+ }
79
+ }
80
+ const personAndAddressUpdater:Updater<Person> =
81
+ Person.Updaters.Core.name(_ => `Dr. ${_}`).then(
82
+ Person.Updaters.Core.surname(_ => `${_}, von`)
83
+ ).then(
84
+ Person.Updaters.Core.address.children.Core.city.Core.name(_ => `${_} the Great`)
85
+ )
86
+ */
@@ -0,0 +1,33 @@
1
+ export type BasicFun<a,b> = (_:a) => b
2
+
3
+ export type Fun<a,b> = BasicFun<a,b> & { then<c>(other:BasicFun<b,c>) : Fun<a,c> }
4
+
5
+ export const Fun = <a,b>(_:BasicFun<a,b>) : Fun<a,b> =>
6
+ Object.assign(_, {
7
+ then: function <c>(this:Fun<a,b>, other:BasicFun<b,c>) : Fun<a,c> {
8
+ return Fun(_ => other(this(_)))
9
+ }
10
+ })
11
+
12
+
13
+ export type BasicFun2<a,b,c> = (_:a, __:b) => c
14
+
15
+ export type Fun2<a,b,c> = BasicFun2<a,b,c> & { then<d>(other:BasicFun<c,d>) : Fun2<a,b,d> }
16
+ export const Fun2 = <a,b,c>(_:BasicFun2<a,b,c>) : Fun2<a,b,c> =>
17
+ Object.assign(_, {
18
+ then: function <d>(this:Fun2<a,b,c>, other:BasicFun<c,d>) : Fun2<a,b,d> {
19
+ return Fun2((a,b) => other(this(a,b)))
20
+ }
21
+ })
22
+
23
+
24
+ /*
25
+ // samples
26
+ const incr: Fun<number,number> = Fun(_ => _ + 1)
27
+ const decr: Fun<number,number> = Fun(_ => _ - 1)
28
+ const doub: Fun<number,number> = Fun(_ => _ * 2)
29
+ const halv: Fun<number,number> = Fun(_ => _ / 2)
30
+
31
+ const f = incr.then(doub).then(decr)
32
+ console.log(f(5)) // prints 11
33
+ */
@@ -0,0 +1,8 @@
1
+ import { CoTypedFactory } from "../../coroutines/builder";
2
+ import { InfiniteStreamReadonlyState, InfiniteStreamWritableState } from "../state";
3
+
4
+ export const StreamCo = <Element extends { id: string }>() =>
5
+ CoTypedFactory<
6
+ InfiniteStreamReadonlyState,
7
+ InfiniteStreamWritableState<Element>
8
+ >();
@@ -0,0 +1,51 @@
1
+ import { AsyncState } from "../../async/state";
2
+ import { replaceWith } from "../../fun/domains/updater/domains/replaceWith/state";
3
+ import { InfiniteStreamState, StreamPosition } from "../state";
4
+ import { StreamCo } from "./builder";
5
+
6
+ export const InfiniteStreamLoader = <Element extends { id: string }>() => {
7
+ const Co = StreamCo<Element>();
8
+ const updaters = InfiniteStreamState<Element>().Updaters;
9
+ // const operations = InfiniteStreamState<Element>().Operations;
10
+
11
+ return Co.Seq([
12
+ Co.SetState(
13
+ updaters.Core.loadingMore(
14
+ replaceWith(AsyncState.Default.loading())
15
+ )
16
+ ),
17
+ Co.While(
18
+ ([current]) => current.loadingMore.kind != "loaded",
19
+ Co.GetState().then((current) => {
20
+ return Co.Await(
21
+ () => current.getChunk([current.position]),
22
+ () => "error" as const
23
+ ).then((apiResult) => {
24
+ if (apiResult.kind == "l") {
25
+ return Co.SetState(
26
+ updaters.Core.loadingMore(
27
+ replaceWith(AsyncState.Default.loaded({}))
28
+ ).then(
29
+ updaters.Coroutine.addLoadedChunk(
30
+ current.position.chunkIndex,
31
+ apiResult.value
32
+ ).then(
33
+ updaters.Core.position(
34
+ StreamPosition.Updaters.Core.shouldLoad(
35
+ replaceWith<StreamPosition["shouldLoad"]>(false)
36
+ )
37
+ )
38
+ )
39
+ )
40
+ );
41
+ } else {
42
+ return Co.Wait(500);
43
+ }
44
+ })
45
+ }
46
+ )
47
+ )
48
+ ])
49
+ };
50
+
51
+ export const Loader = InfiniteStreamLoader
@@ -0,0 +1,12 @@
1
+ import { InfiniteStreamReadonlyState, InfiniteStreamWritableState, InfiniteStreamState } from "../state";
2
+ import { StreamCo } from "./builder";
3
+ import { Loader } from "./infiniteLoader";
4
+
5
+ export const StreamDataLoader =
6
+ <Element extends { id: string }, foreignMutations>() => {
7
+ const operations = InfiniteStreamState<Element>().Operations;
8
+ const LoaderTemplate = StreamCo<Element>().Template<foreignMutations>(Loader<Element>(), {
9
+ runFilter:props => operations.shouldCoroutineRun(props.context)
10
+ })
11
+ return LoaderTemplate.mapContext<InfiniteStreamReadonlyState & InfiniteStreamWritableState<Element>>(_ => _)
12
+ }
@@ -0,0 +1,175 @@
1
+ import { OrderedMap } from "immutable";
2
+ import { BasicUpdater, Updater } from "../fun/domains/updater/state";
3
+ import { replaceWith } from "../fun/domains/updater/domains/replaceWith/state";
4
+ import { simpleUpdater } from "../fun/domains/updater/domains/simpleUpdater/state";
5
+ import { AsyncState } from "../async/state";
6
+ import { Unit } from "../fun/domains/unit/state";
7
+ import { BasicFun } from "../fun/state";
8
+
9
+ export type StreamingStatus = "reload" | "loadMore" | false;
10
+
11
+ type Identifiable = { id: string };
12
+
13
+ export type StreamPosition = {
14
+ chunkSize: number;
15
+ chunkIndex: number;
16
+ shouldLoad: StreamingStatus;
17
+ lastModifiedTime: number;
18
+ };
19
+
20
+ export const StreamPosition = {
21
+ Default: (
22
+ initialChunkSize: number,
23
+ shouldLoad: StreamingStatus = false
24
+ ): StreamPosition => ({
25
+ chunkSize: initialChunkSize,
26
+ chunkIndex: 0,
27
+ shouldLoad,
28
+ lastModifiedTime: Date.now(),
29
+ }),
30
+ Updaters: {
31
+ Template: {
32
+ changeChunkSize: (chunkSize: number): Updater<StreamPosition> =>
33
+ StreamPosition.Updaters.Core.chunkSize(replaceWith(chunkSize)).then(
34
+ StreamPosition.Updaters.Template.reload()
35
+ ),
36
+ reload: (): Updater<StreamPosition> =>
37
+ StreamPosition.Updaters.Core.lastModifiedTime(replaceWith(Date.now()))
38
+ .then(
39
+ StreamPosition.Updaters.Core.shouldLoad(
40
+ replaceWith<StreamPosition["shouldLoad"]>("reload")
41
+ )
42
+ )
43
+ .then(
44
+ StreamPosition.Updaters.Core.chunkIndex(
45
+ replaceWith<StreamPosition["chunkIndex"]>(0)
46
+ )
47
+ ),
48
+ loadMore: (): Updater<StreamPosition> =>
49
+ StreamPosition.Updaters.Core.chunkIndex((_) => _ + 1).then(
50
+ StreamPosition.Updaters.Core.lastModifiedTime(
51
+ replaceWith(Date.now())
52
+ ).then(
53
+ StreamPosition.Updaters.Core.shouldLoad(
54
+ replaceWith<StreamPosition["shouldLoad"]>("loadMore")
55
+ )
56
+ )
57
+ ),
58
+ },
59
+ Core: {
60
+ ...simpleUpdater<StreamPosition>()("lastModifiedTime"),
61
+ ...simpleUpdater<StreamPosition>()("shouldLoad"),
62
+ ...simpleUpdater<StreamPosition>()("chunkIndex"),
63
+ ...simpleUpdater<StreamPosition>()("chunkSize"),
64
+ },
65
+ Coroutine: {},
66
+ },
67
+ };
68
+
69
+ export type Chunk<Element extends Identifiable> = {
70
+ hasMoreValues: boolean;
71
+ data: OrderedMap<Element["id"], Element>;
72
+ };
73
+ export const Chunk = <Element extends Identifiable>() => ({
74
+ Default:(
75
+ hasMoreValues: boolean,
76
+ data: OrderedMap<Element["id"], Element>,
77
+ ) : Chunk<Element> => ({
78
+ hasMoreValues, data
79
+ })
80
+ })
81
+
82
+ export type InfiniteStreamState<Element extends Identifiable> = {
83
+ loadingMore: AsyncState<Unit>;
84
+ loadedElements: OrderedMap<StreamPosition["chunkIndex"], Chunk<Element>>;
85
+ position: StreamPosition;
86
+ getChunk: BasicFun<[StreamPosition], Promise<Chunk<Element>>>;
87
+ };
88
+
89
+ export const InfiniteStreamState = <Element extends Identifiable>() => ({
90
+ Default: (
91
+ initialChunkSize: number,
92
+ getChunk: InfiniteStreamState<Element>["getChunk"],
93
+ shouldLoad?: StreamingStatus
94
+ ): InfiniteStreamState<Element> => ({
95
+ loadingMore: AsyncState.Default.unloaded(),
96
+ loadedElements: OrderedMap(),
97
+ position: StreamPosition.Default(initialChunkSize, shouldLoad),
98
+ getChunk,
99
+ }),
100
+ Operations: {
101
+ shouldCoroutineRun: (current: InfiniteStreamState<Element>): boolean =>
102
+ current.position.shouldLoad != false,
103
+ loadNextPage: (current: InfiniteStreamState<Element>): boolean =>
104
+ current.position.shouldLoad !== false &&
105
+ current.loadedElements.last()?.hasMoreValues !== false,
106
+ },
107
+ Updaters: {
108
+ Coroutine: {
109
+ addLoadedChunk: (
110
+ chunkIndex: number,
111
+ newChunk: Chunk<Element>
112
+ ): Updater<InfiniteStreamState<Element>> =>
113
+ InfiniteStreamState<Element>().Updaters.Core.loadedElements((_) =>
114
+ _.set(chunkIndex, newChunk)
115
+ ),
116
+ },
117
+ Core: {
118
+ ...simpleUpdater<InfiniteStreamState<Element>>()("getChunk"),
119
+ ...simpleUpdater<InfiniteStreamState<Element>>()("loadingMore"),
120
+ ...simpleUpdater<InfiniteStreamState<Element>>()("loadedElements"),
121
+ whenNotAlreadyLoading: (
122
+ _: BasicUpdater<InfiniteStreamState<Element>>
123
+ ): Updater<InfiniteStreamState<Element>> => {
124
+ return Updater((current) => {
125
+ if (InfiniteStreamState<Element>().Operations.loadNextPage(current)) {
126
+ return current;
127
+ }
128
+ return _(current);
129
+ });
130
+ },
131
+ position: (
132
+ positionUpdater: Updater<InfiniteStreamState<Element>["position"]>
133
+ ): Updater<InfiniteStreamState<Element>> =>
134
+ Updater((current) => {
135
+ const newPosition = positionUpdater(current.position);
136
+ let newState = current;
137
+ if (newPosition.chunkSize != current.position.chunkSize)
138
+ newState =
139
+ InfiniteStreamState<Element>().Updaters.Core.clearLoadedElements()(
140
+ newState
141
+ );
142
+ return { ...newState, position: newPosition };
143
+ }),
144
+ clearLoadedElements: (): Updater<InfiniteStreamState<Element>> =>
145
+ InfiniteStreamState<Element>().Updaters.Core.loadedElements((_) =>
146
+ OrderedMap()
147
+ ),
148
+ },
149
+ Template: {
150
+ reload: (
151
+ getChunk: InfiniteStreamState<Element>["getChunk"]
152
+ ): Updater<InfiniteStreamState<Element>> =>
153
+ InfiniteStreamState<Element>()
154
+ .Updaters.Core.position(StreamPosition.Updaters.Template.reload())
155
+ .then(
156
+ InfiniteStreamState<Element>().Updaters.Core.clearLoadedElements()
157
+ )
158
+ .then(
159
+ InfiniteStreamState<Element>().Updaters.Core.getChunk(
160
+ replaceWith(getChunk)
161
+ )
162
+ ),
163
+ loadMore: (): Updater<InfiniteStreamState<Element>> =>
164
+ InfiniteStreamState<Element>().Updaters.Core.whenNotAlreadyLoading(
165
+ InfiniteStreamState<Element>().Updaters.Core.position(
166
+ StreamPosition.Updaters.Template.loadMore()
167
+ )
168
+ ),
169
+ },
170
+ },
171
+ });
172
+
173
+ export type InfiniteStreamReadonlyState = Unit;
174
+ export type InfiniteStreamWritableState<Element extends { id: string }> =
175
+ InfiniteStreamState<Element>;
@@ -0,0 +1,16 @@
1
+ import { Unit } from "../fun/domains/unit/state";
2
+ import { Template } from "../template/state";
3
+ import { StreamDataLoader } from "./coroutines/runner";
4
+ import { InfiniteStreamReadonlyState, InfiniteStreamWritableState } from "./state";
5
+
6
+ export const InfiniteStreamTemplate =
7
+ <Element extends { id: string }>() => Template.Default<
8
+ InfiniteStreamReadonlyState,
9
+ InfiniteStreamWritableState<Element>,
10
+ Unit
11
+ >((_props) =>
12
+ <>{
13
+ }</>
14
+ ).any([
15
+ StreamDataLoader<Element, Unit>()
16
+ ])
@@ -0,0 +1,12 @@
1
+ export const DomRectRepo = {
2
+ Operations:{
3
+ rectanglesIntersect:(r1: DOMRect, r2: DOMRect) => {
4
+ return !(
5
+ r2.left > r1.right ||
6
+ r2.right < r1.left ||
7
+ r2.top > r1.bottom ||
8
+ r2.bottom < r1.top
9
+ );
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,9 @@
1
+ export const numberRepo = {
2
+ Operations:
3
+ {
4
+ lerp: (a: number, min: number, max: number) =>
5
+ min + (max - min) * a,
6
+ clamp: (a: number, min: number, max: number) =>
7
+ Math.max(Math.min(a, max), min),
8
+ }
9
+ }
@@ -0,0 +1,22 @@
1
+ import { Visibility } from "../../../visibility/state";
2
+
3
+ export type Rect = { top: number; left: number; bottom: number; right: number; };
4
+ export const Rect = {
5
+ Operations:{
6
+ IsElementInViewport(rect: Rect, windowRect: Rect): Visibility {
7
+ return rect.top >= 0 &&
8
+ // rect.left >= 0 &&
9
+ rect.bottom <= windowRect.bottom // &&
10
+ ? // rect.right <= windowRect.right
11
+ "fully-visible"
12
+ : !(
13
+ //windowRect.left > rect.right ||
14
+ // windowRect.right < rect.left ||
15
+ (windowRect.top > rect.bottom || windowRect.bottom < rect.top)
16
+ )
17
+ ? "partially-visible"
18
+ : "fully-invisible";
19
+ }
20
+
21
+ }
22
+ }
@@ -0,0 +1,87 @@
1
+ export type RGBAColor = { readonly r: number, readonly g: number, readonly b: number, readonly a: number }
2
+ export const RGBAColor = {
3
+ Default:
4
+ Object.assign((r: number, g: number, b: number, a: number): RGBAColor => ({ r, g, b, a }),
5
+ {
6
+ zero: (): RGBAColor => RGBAColor.Default(0, 0, 0, 0),
7
+ fromHSL: (hue: number, sat: number, light: number): RGBAColor => {
8
+ let t2;
9
+ hue = hue / 60;
10
+ if (light <= 0.5) {
11
+ t2 = light * (sat + 1);
12
+ } else {
13
+ t2 = light + sat - light * sat;
14
+ }
15
+ const t1 = light * 2 - t2;
16
+ const r = RGBAColor.Operations.hueToRgb(t1, t2, hue + 2) * 255;
17
+ const g = RGBAColor.Operations.hueToRgb(t1, t2, hue) * 255;
18
+ const b = RGBAColor.Operations.hueToRgb(t1, t2, hue - 2) * 255;
19
+ return { r: r, g: g, b: b, a: 1.0 };
20
+ },
21
+ }),
22
+
23
+
24
+ Updaters: {
25
+
26
+ },
27
+ Operations: {
28
+ toHsl: ({ r, g, b }: RGBAColor) => {
29
+ let min,
30
+ max,
31
+ i,
32
+ s,
33
+ maxcolor,
34
+ h = 0;
35
+ const rgb = [r / 255, g / 255, b / 255];
36
+ min = rgb[0];
37
+ max = rgb[0];
38
+ maxcolor = 0;
39
+ for (i = 0; i < rgb.length - 1; i++) {
40
+ if (rgb[i + 1] <= min) {
41
+ min = rgb[i + 1];
42
+ }
43
+ if (rgb[i + 1] >= max) {
44
+ max = rgb[i + 1];
45
+ maxcolor = i + 1;
46
+ }
47
+ }
48
+ if (maxcolor == 0) {
49
+ h = (rgb[1] - rgb[2]) / (max - min);
50
+ }
51
+ if (maxcolor == 1) {
52
+ h = 2 + (rgb[2] - rgb[0]) / (max - min);
53
+ }
54
+ if (maxcolor == 2) {
55
+ h = 4 + (rgb[0] - rgb[1]) / (max - min);
56
+ }
57
+ if (isNaN(h)) {
58
+ h = 0;
59
+ }
60
+ h = h * 60;
61
+ if (h < 0) {
62
+ h = h + 360;
63
+ }
64
+ const l = (min + max) / 2;
65
+ if (min == max) {
66
+ s = 0;
67
+ } else {
68
+ if (l < 0.5) {
69
+ s = (max - min) / (max + min);
70
+ } else {
71
+ s = (max - min) / (2 - max - min);
72
+ }
73
+ }
74
+ s = s;
75
+ return { h: h, s: s, l: l };
76
+ },
77
+
78
+ hueToRgb: (t1: number, t2: number, hue: number) => {
79
+ if (hue < 0) hue += 6;
80
+ if (hue >= 6) hue -= 6;
81
+ if (hue < 1) return (t2 - t1) * hue + t1;
82
+ else if (hue < 3) return t2;
83
+ else if (hue < 4) return (t2 - t1) * (4 - hue) + t1;
84
+ else return t1;
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,14 @@
1
+ export type Size2 = { readonly width:number, readonly height:number }
2
+ export const Size2 = {
3
+ Default:
4
+ Object.assign((width:number,height:number) : Size2 => ({ width, height }),
5
+ {
6
+ zero:() : Size2 => Size2.Default(0,0),
7
+ }),
8
+ Updaters:{
9
+
10
+ },
11
+ Operations:{
12
+
13
+ }
14
+ }
@@ -0,0 +1,16 @@
1
+ export type Vector2 = { readonly x:number, readonly y:number }
2
+ export const Vector2 = {
3
+ Default:
4
+ Object.assign((x:number,y:number) : Vector2 => ({ x, y }),
5
+ {
6
+ zero:() : Vector2 => Vector2.Default(0,0),
7
+ one_x:() : Vector2 => Vector2.Default(1,0),
8
+ one_y:() : Vector2 => Vector2.Default(0,1),
9
+ }),
10
+ Updaters:{
11
+
12
+ },
13
+ Operations:{
14
+
15
+ }
16
+ }
@@ -0,0 +1,42 @@
1
+ import { OrderedMap } from "immutable";
2
+ import { Guid, Unit, SynchronizationResult } from "../../main";
3
+ import { CoTypedFactory } from "../coroutines/builder";
4
+ import { Coroutine } from "../coroutines/state";
5
+ import { BasicFun } from "../fun/state";
6
+
7
+
8
+ export const QueueCoroutine = <Context, State>(
9
+ removeItem: BasicFun<Guid, Coroutine<Context & State, State, Unit>>,
10
+ getItemsToProcess: BasicFun<Context & State, OrderedMap<Guid, {
11
+ preprocess: Coroutine<Context & State, State, Unit>;
12
+ operation: Coroutine<Context & State, State, SynchronizationResult>;
13
+ postprocess: BasicFun<SynchronizationResult, Coroutine<Context & State, State, Unit>>;
14
+ reenqueue: Coroutine<Context & State, State, Unit>;
15
+ }>>
16
+ ): Coroutine<Context & State, State, Unit> => {
17
+ const Co = CoTypedFactory<Context, State>();
18
+
19
+ return Co.Repeat(
20
+ Co.GetState().then(current => {
21
+ let operations = getItemsToProcess(current);
22
+
23
+ return Co.Seq([
24
+ Co.All(
25
+ operations.toArray()
26
+ .map(([id, k]) => k.preprocess.then(() => k.operation)
27
+ .then(_ =>
28
+ // alert(`${JSON.stringify(k)} => ${_}\n`)
29
+ k.postprocess(_).then(() => {
30
+ if (_ == "completed") {
31
+ return Co.Return({});
32
+ } else {
33
+ return k.reenqueue;
34
+ }
35
+ })
36
+ ).then(() => removeItem(id))
37
+ )
38
+ ),
39
+ ]);
40
+ })
41
+ );
42
+ };
@@ -0,0 +1,14 @@
1
+ import { ForeignMutationsInput } from "../../../foreignMutations/state";
2
+ import { Unit } from "../../../fun/domains/unit/state";
3
+ import { BasicFun } from "../../../fun/state";
4
+
5
+ export type Updaters = {
6
+ Core: Unit; Template: Unit; Coroutine: Unit;
7
+ }
8
+
9
+ export type Repository<Context, State, Input, ActualUpdaters extends Updaters, Operations = Unit> = {
10
+ Default: BasicFun<Input, State>;
11
+ Updaters: ActualUpdaters;
12
+ Operations: Operations;
13
+ ForeignMutations: BasicFun<ForeignMutationsInput<Context, State>, Unit>;
14
+ };