@ersbeth/picoflow 2.0.2 → 2.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.
Files changed (152) hide show
  1. package/README.md +10 -0
  2. package/SKILL.md +106 -0
  3. package/package.json +5 -1
  4. package/.gitlab-ci.yml +0 -24
  5. package/.vscode/settings.json +0 -5
  6. package/CHANGELOG.md +0 -94
  7. package/biome.json +0 -47
  8. package/docs/.vitepress/config.mts +0 -145
  9. package/docs/api/functions/array.md +0 -35
  10. package/docs/api/functions/constant.md +0 -33
  11. package/docs/api/functions/constantAsync.md +0 -69
  12. package/docs/api/functions/derivation.md +0 -34
  13. package/docs/api/functions/derivationAsync.md +0 -34
  14. package/docs/api/functions/from.md +0 -129
  15. package/docs/api/functions/isDisposable.md +0 -27
  16. package/docs/api/functions/map.md +0 -36
  17. package/docs/api/functions/signal.md +0 -21
  18. package/docs/api/functions/state.md +0 -67
  19. package/docs/api/functions/stateAsync.md +0 -69
  20. package/docs/api/functions/subscribe.md +0 -40
  21. package/docs/api/functions/writableDerivation.md +0 -33
  22. package/docs/api/functions/writableDerivationAsync.md +0 -34
  23. package/docs/api/index.md +0 -61
  24. package/docs/api/interfaces/FlowArray.md +0 -439
  25. package/docs/api/interfaces/FlowConstant.md +0 -220
  26. package/docs/api/interfaces/FlowConstantAsync.md +0 -221
  27. package/docs/api/interfaces/FlowDerivation.md +0 -241
  28. package/docs/api/interfaces/FlowDerivationAsync.md +0 -242
  29. package/docs/api/interfaces/FlowDisposable.md +0 -59
  30. package/docs/api/interfaces/FlowEffect.md +0 -64
  31. package/docs/api/interfaces/FlowMap.md +0 -374
  32. package/docs/api/interfaces/FlowObservable.md +0 -155
  33. package/docs/api/interfaces/FlowSignal.md +0 -156
  34. package/docs/api/interfaces/FlowState.md +0 -269
  35. package/docs/api/interfaces/FlowStateAsync.md +0 -268
  36. package/docs/api/interfaces/FlowSubscribable.md +0 -55
  37. package/docs/api/interfaces/FlowTracker.md +0 -61
  38. package/docs/api/interfaces/FlowValue.md +0 -222
  39. package/docs/api/interfaces/FlowWritableDerivation.md +0 -292
  40. package/docs/api/interfaces/FlowWritableDerivationAsync.md +0 -293
  41. package/docs/api/type-aliases/DerivationFunction.md +0 -28
  42. package/docs/api/type-aliases/DerivationFunctionAsync.md +0 -28
  43. package/docs/api/type-aliases/FlowArrayAction.md +0 -60
  44. package/docs/api/type-aliases/FlowDataTracker.md +0 -33
  45. package/docs/api/type-aliases/FlowMapAction.md +0 -48
  46. package/docs/api/type-aliases/FlowOnDataListener.md +0 -33
  47. package/docs/api/type-aliases/FlowOnErrorListener.md +0 -27
  48. package/docs/api/type-aliases/FlowOnPendingListener.md +0 -21
  49. package/docs/api/type-aliases/FlowReadonly.md +0 -22
  50. package/docs/api/type-aliases/InitFunction.md +0 -21
  51. package/docs/api/type-aliases/InitFunctionAsync.md +0 -21
  52. package/docs/api/type-aliases/NotPromise.md +0 -21
  53. package/docs/api/type-aliases/UpdateFunction.md +0 -27
  54. package/docs/api/type-aliases/UpdateFunctionAsync.md +0 -27
  55. package/docs/api/typedoc-sidebar.json +0 -65
  56. package/docs/examples/examples.md +0 -2311
  57. package/docs/examples/patterns.md +0 -649
  58. package/docs/guide/advanced/architecture.md +0 -1234
  59. package/docs/guide/advanced/disposal.md +0 -426
  60. package/docs/guide/advanced/migration-v1.md +0 -464
  61. package/docs/guide/advanced/migration-v2.md +0 -204
  62. package/docs/guide/advanced/solidjs.md +0 -135
  63. package/docs/guide/introduction/concepts.md +0 -57
  64. package/docs/guide/introduction/conventions.md +0 -30
  65. package/docs/guide/introduction/getting-started.md +0 -139
  66. package/docs/guide/introduction/lifecycle.md +0 -368
  67. package/docs/guide/primitives/array.md +0 -286
  68. package/docs/guide/primitives/constant.md +0 -207
  69. package/docs/guide/primitives/derivations.md +0 -281
  70. package/docs/guide/primitives/effects.md +0 -372
  71. package/docs/guide/primitives/map.md +0 -265
  72. package/docs/guide/primitives/overview.md +0 -92
  73. package/docs/guide/primitives/signal.md +0 -222
  74. package/docs/guide/primitives/state.md +0 -272
  75. package/docs/index.md +0 -47
  76. package/docs/public/logo.svg +0 -1
  77. package/src/api/base/flowDisposable.ts +0 -44
  78. package/src/api/base/flowObservable.ts +0 -28
  79. package/src/api/base/flowSubscribable.ts +0 -87
  80. package/src/api/base/flowTracker.ts +0 -7
  81. package/src/api/base/index.ts +0 -4
  82. package/src/api/index.ts +0 -2
  83. package/src/api/nodes/async/flowConstantAsync.ts +0 -36
  84. package/src/api/nodes/async/flowDerivationAsync.ts +0 -42
  85. package/src/api/nodes/async/flowStateAsync.ts +0 -47
  86. package/src/api/nodes/async/flowWritableDerivationAsync.ts +0 -33
  87. package/src/api/nodes/async/index.ts +0 -4
  88. package/src/api/nodes/collections/flowArray.ts +0 -155
  89. package/src/api/nodes/collections/flowMap.ts +0 -115
  90. package/src/api/nodes/collections/index.ts +0 -2
  91. package/src/api/nodes/flowEffect.ts +0 -42
  92. package/src/api/nodes/flowSignal.ts +0 -28
  93. package/src/api/nodes/flowValue.ts +0 -37
  94. package/src/api/nodes/index.ts +0 -7
  95. package/src/api/nodes/sync/flowConstant.ts +0 -33
  96. package/src/api/nodes/sync/flowDerivation.ts +0 -41
  97. package/src/api/nodes/sync/flowState.ts +0 -45
  98. package/src/api/nodes/sync/flowWritableDerivation.ts +0 -31
  99. package/src/api/nodes/sync/index.ts +0 -4
  100. package/src/api/nodes/utils.ts +0 -24
  101. package/src/base/disposable.ts +0 -18
  102. package/src/base/executionStack.ts +0 -42
  103. package/src/base/index.ts +0 -5
  104. package/src/base/node.ts +0 -98
  105. package/src/base/observable.ts +0 -92
  106. package/src/base/observer.ts +0 -51
  107. package/src/converters/index.ts +0 -1
  108. package/src/converters/solid.ts +0 -109
  109. package/src/index.ts +0 -2
  110. package/src/nodes/arrayNode.ts +0 -180
  111. package/src/nodes/effectNode.ts +0 -58
  112. package/src/nodes/index.ts +0 -7
  113. package/src/nodes/mapNode.ts +0 -125
  114. package/src/nodes/signalNode.ts +0 -19
  115. package/src/nodes/valueAsyncNode.ts +0 -85
  116. package/src/nodes/valueNode.ts +0 -148
  117. package/src/nodes/valueSyncNode.ts +0 -125
  118. package/src/schedulers/asyncResolver.ts +0 -78
  119. package/src/schedulers/asyncScheduler.ts +0 -66
  120. package/src/schedulers/index.ts +0 -4
  121. package/src/schedulers/pendingError.ts +0 -13
  122. package/src/schedulers/scheduler.ts +0 -9
  123. package/src/schedulers/syncResolver.ts +0 -69
  124. package/src/schedulers/syncScheduler.ts +0 -55
  125. package/test/base/pendingError.test.ts +0 -67
  126. package/test/converters/solid.derivation.browser.test.tsx +0 -69
  127. package/test/converters/solid.node.test.ts +0 -654
  128. package/test/converters/solid.state.browser.test.tsx +0 -1592
  129. package/test/reactivity/flowSignal.test.ts +0 -226
  130. package/test/reactivity/nodes/async/asyncScheduler/asyncResolver.test.ts +0 -593
  131. package/test/reactivity/nodes/async/asyncScheduler/asyncScheduler.test.ts +0 -317
  132. package/test/reactivity/nodes/async/flowConstantAsync.test.ts +0 -652
  133. package/test/reactivity/nodes/async/flowDerivation.test.ts +0 -898
  134. package/test/reactivity/nodes/async/flowDerivationAsync.test.ts +0 -1716
  135. package/test/reactivity/nodes/async/flowStateAsync.test.ts +0 -708
  136. package/test/reactivity/nodes/async/flowWritableDerivationAsync.test.ts +0 -614
  137. package/test/reactivity/nodes/collections/flowArray.asyncStates.test.ts +0 -1289
  138. package/test/reactivity/nodes/collections/flowArray.scalars.test.ts +0 -961
  139. package/test/reactivity/nodes/collections/flowArray.states.test.ts +0 -1035
  140. package/test/reactivity/nodes/collections/flowMap.asyncStates.test.ts +0 -960
  141. package/test/reactivity/nodes/collections/flowMap.scalars.test.ts +0 -775
  142. package/test/reactivity/nodes/collections/flowMap.states.test.ts +0 -958
  143. package/test/reactivity/nodes/sync/flowConstant.test.ts +0 -377
  144. package/test/reactivity/nodes/sync/flowDerivation.test.ts +0 -896
  145. package/test/reactivity/nodes/sync/flowState.test.ts +0 -341
  146. package/test/reactivity/nodes/sync/flowWritableDerivation.test.ts +0 -603
  147. package/test/vitest.d.ts +0 -10
  148. package/tsconfig.json +0 -37
  149. package/typedoc.json +0 -37
  150. package/vite.config.ts +0 -31
  151. package/vitest.browser.config.ts +0 -21
  152. package/vitest.config.ts +0 -17
@@ -1,125 +0,0 @@
1
- import type { DerivationFunction, InitFunction, NotPromise, UpdateFunction } from "../api";
2
- import { SyncScheduler } from "../schedulers";
3
- import { ValueNode } from "./valueNode";
4
-
5
- /**
6
- * Function that computes a value (either initialization or derivation).
7
- * @internal
8
- */
9
- export type ComputeFunction<T> = InitFunction<T> | DerivationFunction<T>;
10
-
11
- /**
12
- * Synchronous reactive value that computes immediately without async scheduling.
13
- * @internal
14
- */
15
- export class ValueSyncNode<T extends NotPromise<unknown>> extends ValueNode<T> {
16
- protected _scheduler: SyncScheduler<T>;
17
- private _compute: () => T;
18
-
19
- constructor(valueOrCompute: NotPromise<T> | ComputeFunction<T>) {
20
- super();
21
- if (typeof valueOrCompute === "function") {
22
- // compute is a function
23
- // @ts-expect-error valueOrCompute is a function
24
- this._compute = () => valueOrCompute(this, this._value);
25
- } else {
26
- // compute is a value
27
- this._compute = () => valueOrCompute;
28
- }
29
-
30
- this.status = "dirty";
31
- this._scheduler = new SyncScheduler<T>(
32
- () => this._compute(),
33
- (value) => this._onResolve(value as NotPromise<T>),
34
- (error) => this._onReject(error),
35
- );
36
-
37
- if (typeof valueOrCompute !== "function") {
38
- this._scheduler.compute();
39
- }
40
- }
41
-
42
- private _onResolve(value: NotPromise<T>) {
43
- this.status = "resolved";
44
- this._value = value;
45
- this._error = undefined;
46
- }
47
-
48
- private _onReject(error: unknown) {
49
- this.status = "error";
50
- this._error = error;
51
- }
52
-
53
- set(value: NotPromise<T>): void;
54
- set(updater: UpdateFunction<T>): void;
55
- set(valueOrUpdater: NotPromise<T> | UpdateFunction<T>): void {
56
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
57
-
58
- if (typeof valueOrUpdater === "function") {
59
- const updater = valueOrUpdater as UpdateFunction<T>;
60
- switch (this.status) {
61
- case "resolved": {
62
- const nextValue = updater(this._value);
63
- if (nextValue === this._value) return;
64
- this.status = "pending";
65
- this._scheduler.overwrite(nextValue);
66
- this.notifyDependents();
67
- return;
68
- }
69
- case "pending":
70
- case "error":
71
- case "dirty": {
72
- // TODO: For now we use latest value to compute the next value
73
- // Maybe we should throw instead ?
74
- const nextValue = updater(this._value);
75
- this.status = "pending";
76
- this._scheduler.overwrite(nextValue);
77
- this.notifyDependents();
78
- return;
79
- }
80
- }
81
- } else {
82
- const nextValue = valueOrUpdater;
83
- switch (this.status) {
84
- case "resolved": {
85
- if (nextValue === this._value) return;
86
- this.status = "pending";
87
- this._scheduler.overwrite(nextValue);
88
- this.notifyDependents();
89
- return;
90
- }
91
- case "pending":
92
- case "error":
93
- case "dirty": {
94
- this.status = "pending";
95
- this._scheduler.overwrite(nextValue);
96
- this.notifyDependents();
97
- return;
98
- }
99
- }
100
- }
101
- }
102
-
103
- refresh(): void {
104
- if (this.disposed) throw new Error("[PicoFlow] Primitive is disposed");
105
-
106
- const currentValue = this._value;
107
- const currentStatus = this.status;
108
- this.execute();
109
-
110
- switch (this.status) {
111
- case "resolved": {
112
- const nextValue = this._value;
113
- if (nextValue === currentValue && currentStatus === this.status) return;
114
- this.notifyDependents();
115
- return;
116
- }
117
- case "error":
118
- case "pending":
119
- case "dirty": {
120
- this.notifyDependents();
121
- return;
122
- }
123
- }
124
- }
125
- }
@@ -1,78 +0,0 @@
1
- import { PendingError } from "./pendingError";
2
-
3
- /**
4
- * Manages asynchronous computation lifecycle with iteration tracking to prevent race conditions.
5
- * @internal
6
- */
7
- export class AsyncResolver<T> {
8
- private readonly _compute: () => Promise<T>;
9
- private readonly _computed = Promise.withResolvers<T>();
10
- private _iteration = 0;
11
- private _aborted = false;
12
- private _finished = false;
13
-
14
- constructor(compute: () => Promise<T>) {
15
- this._compute = compute;
16
-
17
- // Prevent unhandled rejections before finally block is executed: catch all errors so they don't propagate.
18
- // Actual error handling occurs elsewhere in ComputationScheduler through proper promise chaining.
19
- this._computed.promise
20
- .catch(() => {})
21
- .finally(() => {
22
- this._finished = true;
23
- });
24
- }
25
-
26
- get computed(): Promise<T> {
27
- return this._computed.promise;
28
- }
29
-
30
- get aborted(): boolean {
31
- return this._aborted;
32
- }
33
-
34
- get finished(): boolean {
35
- return this._finished;
36
- }
37
-
38
- compute(): void {
39
- if (this._finished) throw new Error("[Picoflow] PendingResolver: Can't restart a settled resolver");
40
- if (this._aborted) throw new Error("[Picoflow] PendingResolver: Can't restart an aborted resolver");
41
-
42
- this._iteration++;
43
- const currentIteration = this._iteration;
44
- this._compute()
45
- .then((value) => {
46
- if (this._iteration === currentIteration && !this._aborted) this._computed.resolve(value);
47
- })
48
- .catch((error) => {
49
- if (this._iteration === currentIteration && !this._aborted) {
50
- if (!(error instanceof PendingError)) {
51
- this._computed.reject(error);
52
- }
53
- }
54
- });
55
- }
56
-
57
- overwrite(promise: Promise<T>): void {
58
- if (this._finished) throw new Error("[Picoflow] PendingResolver: Can't overwrite a settled resolver");
59
- if (this._aborted) throw new Error("[Picoflow] PendingResolver: Can't overwrite an aborted resolver");
60
-
61
- this._iteration++;
62
- const currentIteration = this._iteration;
63
- promise
64
- .then((value) => {
65
- if (this._iteration === currentIteration && !this._aborted) this._computed.resolve(value);
66
- })
67
- .catch((error) => {
68
- if (this._iteration === currentIteration && !this._aborted) {
69
- this._computed.reject(error);
70
- }
71
- });
72
- }
73
-
74
- abort(): void {
75
- this._iteration++;
76
- this._aborted = true;
77
- }
78
- }
@@ -1,66 +0,0 @@
1
- import { AsyncResolver } from "./asyncResolver";
2
- import type { Scheduler } from "./scheduler";
3
-
4
- /**
5
- * Scheduler that manages asynchronous computation lifecycle with resolver instances.
6
- * @internal
7
- */
8
- export class AsyncScheduler<T> implements Scheduler {
9
- private readonly _compute: () => Promise<T>;
10
- private _resolver: AsyncResolver<T>;
11
- private _onResolve: (value: T) => void;
12
- private _onReject: (error: unknown) => void;
13
- private _settled = Promise.withResolvers<void>();
14
- private _disposed = false;
15
-
16
- constructor(compute: () => Promise<T>, onResolve: (value: T) => void, onReject: (error: unknown) => void) {
17
- this._compute = compute;
18
- this._onResolve = onResolve;
19
- this._onReject = onReject;
20
- this._resolver = new AsyncResolver(compute);
21
- this._resolver.computed
22
- .then(this._onResolve)
23
- .catch(this._onReject)
24
- .finally(() => this._settled.resolve());
25
- }
26
-
27
- get settled(): Promise<void> {
28
- if (this._disposed) throw new Error("[PicoFlow] ComputationScheduler is disposed");
29
- return this._settled.promise;
30
- }
31
-
32
- get disposed(): boolean {
33
- return this._disposed;
34
- }
35
-
36
- overwrite(promise: Promise<T>): void {
37
- if (this._disposed) throw new Error("[PicoFlow] ComputationScheduler is disposed");
38
- if (this._resolver.finished) {
39
- this._resolver = new AsyncResolver(this._compute);
40
- this._settled = Promise.withResolvers<void>();
41
- this._resolver.computed
42
- .then(this._onResolve)
43
- .catch(this._onReject)
44
- .finally(() => this._settled.resolve());
45
- }
46
- this._resolver.overwrite(promise);
47
- }
48
-
49
- compute(): void {
50
- if (this._disposed) throw new Error("[PicoFlow] ComputationScheduler is disposed");
51
- if (this._resolver.finished) {
52
- this._resolver = new AsyncResolver(this._compute);
53
- this._settled = Promise.withResolvers<void>();
54
- this._resolver.computed
55
- .then(this._onResolve)
56
- .catch(this._onReject)
57
- .finally(() => this._settled.resolve());
58
- }
59
- this._resolver.compute();
60
- }
61
-
62
- dispose(): void {
63
- this._resolver.abort();
64
- this._disposed = true;
65
- }
66
- }
@@ -1,4 +0,0 @@
1
- export * from "./asyncScheduler";
2
- export * from "./pendingError";
3
- export * from "./scheduler";
4
- export * from "./syncScheduler";
@@ -1,13 +0,0 @@
1
- /**
2
- * Error thrown when an async computation is pending, encapsulating its promise for cascading dependencies.
3
- * @internal
4
- */
5
- export class PendingError extends Error {
6
- readonly pendingPromise: Promise<unknown>;
7
-
8
- constructor(promise: Promise<unknown>) {
9
- super("[PicoFlow] PendingResolver pending");
10
- this.name = "PendingError";
11
- this.pendingPromise = promise;
12
- }
13
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Contract for schedulers that coordinate reactive computations and their lifecycle.
3
- * @internal
4
- */
5
- export interface Scheduler {
6
- compute(): void;
7
- dispose(): void;
8
- settled: Promise<void>;
9
- }
@@ -1,69 +0,0 @@
1
- import { PendingError } from "./pendingError";
2
-
3
- /**
4
- * Manages synchronous computation lifecycle with iteration tracking to prevent race conditions.
5
- * @internal
6
- */
7
- export class SyncResolver<T> {
8
- private readonly _compute: () => T;
9
- private _iteration = 0;
10
- private _aborted = false;
11
- private _finished = false;
12
-
13
- private _onValue: (value: T) => void;
14
- private _onError: (error: unknown) => void;
15
-
16
- constructor(compute: () => T, onValue: (value: T) => void, onError: (error: unknown) => void) {
17
- this._compute = compute;
18
- this._onValue = onValue;
19
- this._onError = onError;
20
- }
21
-
22
- get aborted(): boolean {
23
- return this._aborted;
24
- }
25
-
26
- get finished(): boolean {
27
- return this._finished;
28
- }
29
-
30
- compute(): void {
31
- if (this._finished) throw new Error("[Picoflow] PendingResolver: Can't restart a settled resolver");
32
- if (this._aborted) throw new Error("[Picoflow] PendingResolver: Can't restart an aborted resolver");
33
-
34
- this._iteration++;
35
- const currentIteration = this._iteration;
36
- try {
37
- const value = this._compute();
38
- if (this._iteration === currentIteration && !this._aborted) {
39
- this._finished = true;
40
- this._onValue(value);
41
- }
42
- } catch (error) {
43
- if (this._iteration === currentIteration && !this._aborted) {
44
- if (!(error instanceof PendingError)) {
45
- this._finished = true;
46
- this._onError(error);
47
- }
48
- }
49
- }
50
- }
51
-
52
- overwrite(value: T): void {
53
- if (this._finished) throw new Error("[Picoflow] PendingResolver: Can't overwrite a settled resolver");
54
- if (this._aborted) throw new Error("[Picoflow] PendingResolver: Can't overwrite an aborted resolver");
55
-
56
- this._iteration++;
57
- const currentIteration = this._iteration;
58
-
59
- if (this._iteration === currentIteration && !this._aborted) {
60
- this._finished = true;
61
- this._onValue(value);
62
- }
63
- }
64
-
65
- abort(): void {
66
- this._iteration++;
67
- this._aborted = true;
68
- }
69
- }
@@ -1,55 +0,0 @@
1
- import type { Scheduler } from "./scheduler";
2
- import { SyncResolver } from "./syncResolver";
3
-
4
- /**
5
- * Scheduler that manages synchronous computation lifecycle with resolver instances.
6
- * @internal
7
- */
8
- export class SyncScheduler<T> implements Scheduler {
9
- private readonly _compute: () => T;
10
- private _resolver: SyncResolver<T>;
11
- private _onResolve: (value: T) => void;
12
- private _onReject: (error: unknown) => void;
13
- private _settled = Promise.withResolvers<void>();
14
- private _disposed = false;
15
-
16
- constructor(compute: () => T, onResolve: (value: T) => void, onReject: (error: unknown) => void) {
17
- this._compute = compute;
18
- this._onResolve = (value) => {
19
- onResolve(value);
20
- this._settled.resolve();
21
- };
22
- this._onReject = (error) => {
23
- onReject(error);
24
- this._settled.resolve();
25
- };
26
- this._resolver = new SyncResolver(compute, this._onResolve, this._onReject);
27
- }
28
-
29
- get settled(): Promise<void> {
30
- return this._settled.promise;
31
- }
32
-
33
- overwrite(value: T): void {
34
- if (this._disposed) throw new Error("[PicoFlow] ComputationScheduler is disposed");
35
- if (this._resolver.finished) {
36
- this._settled = Promise.withResolvers<void>();
37
- this._resolver = new SyncResolver(this._compute, this._onResolve, this._onReject);
38
- }
39
- this._resolver.overwrite(value);
40
- }
41
-
42
- compute(): void {
43
- if (this._disposed) throw new Error("[PicoFlow] ComputationScheduler is disposed");
44
- if (this._resolver.finished) {
45
- this._settled = Promise.withResolvers<void>();
46
- this._resolver = new SyncResolver(this._compute, this._onResolve, this._onReject);
47
- }
48
- this._resolver.compute();
49
- }
50
-
51
- dispose(): void {
52
- this._resolver.abort();
53
- this._disposed = true;
54
- }
55
- }
@@ -1,67 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { PendingError } from "../../src/schedulers";
3
-
4
- describe("PendingError", () => {
5
- describe("constructor and properties", () => {
6
- it("should create instance with pending promise", () => {
7
- const promise = Promise.resolve(42);
8
- const error = new PendingError(promise);
9
-
10
- expect(error).toBeInstanceOf(PendingError);
11
- expect(error.pendingPromise).toBe(promise);
12
- });
13
-
14
- it("should have correct name", () => {
15
- const promise = Promise.resolve(42);
16
- const error = new PendingError(promise);
17
-
18
- expect(error.name).toBe("PendingError");
19
- });
20
-
21
- it("should have correct message", () => {
22
- const promise = Promise.resolve(42);
23
- const error = new PendingError(promise);
24
-
25
- expect(error.message).toBe("[PicoFlow] PendingResolver pending");
26
- });
27
-
28
- it("should extend Error", () => {
29
- const promise = Promise.resolve(42);
30
- const error = new PendingError(promise);
31
-
32
- expect(error).toBeInstanceOf(Error);
33
- });
34
-
35
- it("should store pendingPromise property correctly", async () => {
36
- const promise = Promise.resolve("test-value");
37
- const error = new PendingError(promise);
38
-
39
- expect(error.pendingPromise).toBe(promise);
40
- expect(await error.pendingPromise).toBe("test-value");
41
- });
42
- });
43
-
44
- describe("pendingPromise behavior", () => {
45
- it("should expose the pending promise", () => {
46
- const promise = Promise.resolve(100);
47
- const error = new PendingError(promise);
48
-
49
- expect(error.pendingPromise).toBe(promise);
50
- });
51
-
52
- it("should allow awaiting the pending promise", async () => {
53
- const promise = Promise.resolve("resolved-value");
54
- const error = new PendingError(promise);
55
-
56
- const result = await error.pendingPromise;
57
- expect(result).toBe("resolved-value");
58
- });
59
-
60
- it("should allow awaiting rejected promise", async () => {
61
- const promise = Promise.reject(new Error("test-error"));
62
- const error = new PendingError(promise);
63
-
64
- await expect(error.pendingPromise).rejects.toThrow("test-error");
65
- });
66
- });
67
- });
@@ -1,69 +0,0 @@
1
- import { cleanup, render } from "@solidjs/testing-library";
2
- import { type Component, Match, Switch } from "solid-js";
3
- import { beforeEach, describe, expect, it, vi } from "vitest";
4
- import { userEvent } from "vitest/browser";
5
- import { derivation, from } from "~";
6
-
7
- describe("solid converter", () => {
8
- beforeEach(() => {
9
- cleanup();
10
- });
11
-
12
- describe("updates", () => {
13
- describe("error", () => {
14
- describe("flag", () => {
15
- it("update-error-flag: should handle error in FlowDerivation", async () => {
16
- const Comp: Component = () => {
17
- let condition = false;
18
- const $derivation = derivation(() => {
19
- if (condition) {
20
- throw new Error("Test error");
21
- }
22
- return 42;
23
- });
24
-
25
- const $$derivation = from($derivation);
26
-
27
- return (
28
- <div>
29
- <Switch>
30
- <Match when={$$derivation.error}>
31
- <div>Error</div>
32
- </Match>
33
- <Match when={$$derivation()}>
34
- <div>{$$derivation()}</div>
35
- </Match>
36
- </Switch>
37
- <button
38
- type="button"
39
- onClick={() => {
40
- condition = true;
41
- $derivation.refresh();
42
- }}
43
- >
44
- Update Error
45
- </button>
46
- <button
47
- type="button"
48
- onClick={() => {
49
- condition = false;
50
- $derivation.refresh();
51
- }}
52
- >
53
- Update Value
54
- </button>
55
- </div>
56
- );
57
- };
58
-
59
- const { getByText } = render(() => <Comp />);
60
- await vi.waitFor(() => expect.element(getByText("42")).toBeInTheDocument());
61
- await userEvent.click(getByText("Update Error"));
62
- await vi.waitFor(() => expect.element(getByText("Error")).toBeInTheDocument());
63
- await userEvent.click(getByText("Update Value"));
64
- await vi.waitFor(() => expect.element(getByText("42")).toBeInTheDocument());
65
- });
66
- });
67
- });
68
- });
69
- });