synstate 3.0.5 → 3.1.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 (174) hide show
  1. package/README.md +1 -1
  2. package/dist/core/base/create-observable-base.d.mts +53 -8
  3. package/dist/core/base/create-observable-base.d.mts.map +1 -1
  4. package/dist/core/base/create-observable-base.mjs +48 -17
  5. package/dist/core/base/create-observable-base.mjs.map +1 -1
  6. package/dist/core/base/create-root-observable.d.mts +1 -1
  7. package/dist/core/base/create-root-observable.d.mts.map +1 -1
  8. package/dist/core/combine/combine.d.mts +2 -2
  9. package/dist/core/combine/combine.d.mts.map +1 -1
  10. package/dist/core/combine/merge.d.mts +2 -2
  11. package/dist/core/combine/merge.d.mts.map +1 -1
  12. package/dist/core/combine/zip.d.mts +2 -2
  13. package/dist/core/combine/zip.d.mts.map +1 -1
  14. package/dist/core/create/counter.d.mts +1 -1
  15. package/dist/core/create/counter.d.mts.map +1 -1
  16. package/dist/core/create/from-abortable-promise.d.mts +1 -1
  17. package/dist/core/create/from-abortable-promise.d.mts.map +1 -1
  18. package/dist/core/create/from-promise.d.mts +1 -1
  19. package/dist/core/create/from-promise.d.mts.map +1 -1
  20. package/dist/core/create/from-subscribable.d.mts +1 -1
  21. package/dist/core/create/from-subscribable.d.mts.map +1 -1
  22. package/dist/core/create/just.d.mts +1 -1
  23. package/dist/core/create/just.d.mts.map +1 -1
  24. package/dist/core/create/source.d.mts +1 -1
  25. package/dist/core/create/source.d.mts.map +1 -1
  26. package/dist/core/create/timer.d.mts +1 -1
  27. package/dist/core/create/timer.d.mts.map +1 -1
  28. package/dist/core/operators/audit.d.mts +1 -1
  29. package/dist/core/operators/audit.d.mts.map +1 -1
  30. package/dist/core/operators/debounce.d.mts +1 -1
  31. package/dist/core/operators/debounce.d.mts.map +1 -1
  32. package/dist/core/operators/filter.d.mts +1 -1
  33. package/dist/core/operators/filter.d.mts.map +1 -1
  34. package/dist/core/operators/map.d.mts +1 -1
  35. package/dist/core/operators/map.d.mts.map +1 -1
  36. package/dist/core/operators/merge-map.d.mts +1 -1
  37. package/dist/core/operators/merge-map.d.mts.map +1 -1
  38. package/dist/core/operators/pairwise.d.mts +2 -2
  39. package/dist/core/operators/pairwise.d.mts.map +1 -1
  40. package/dist/core/operators/scan.d.mts +1 -1
  41. package/dist/core/operators/scan.d.mts.map +1 -1
  42. package/dist/core/operators/skip-if-no-change.d.mts +1 -1
  43. package/dist/core/operators/skip-if-no-change.d.mts.map +1 -1
  44. package/dist/core/operators/skip-until.d.mts +1 -1
  45. package/dist/core/operators/skip-until.d.mts.map +1 -1
  46. package/dist/core/operators/skip-while.d.mts +1 -1
  47. package/dist/core/operators/skip-while.d.mts.map +1 -1
  48. package/dist/core/operators/switch-map.d.mts +1 -1
  49. package/dist/core/operators/switch-map.d.mts.map +1 -1
  50. package/dist/core/operators/take-until.d.mts +1 -1
  51. package/dist/core/operators/take-until.d.mts.map +1 -1
  52. package/dist/core/operators/take-while.d.mts +1 -1
  53. package/dist/core/operators/take-while.d.mts.map +1 -1
  54. package/dist/core/operators/throttle.d.mts +1 -1
  55. package/dist/core/operators/throttle.d.mts.map +1 -1
  56. package/dist/core/operators/with-buffered-from.d.mts +1 -1
  57. package/dist/core/operators/with-buffered-from.d.mts.map +1 -1
  58. package/dist/core/operators/with-current-value-from.d.mts +1 -1
  59. package/dist/core/operators/with-current-value-from.d.mts.map +1 -1
  60. package/dist/core/operators/with-initial-value.d.mts +1 -1
  61. package/dist/core/operators/with-initial-value.d.mts.map +1 -1
  62. package/dist/core/predefined/operators/attach-index.d.mts +2 -2
  63. package/dist/core/predefined/operators/attach-index.d.mts.map +1 -1
  64. package/dist/core/predefined/operators/map-optional.d.mts +1 -1
  65. package/dist/core/predefined/operators/map-optional.d.mts.map +1 -1
  66. package/dist/core/predefined/operators/map-result-err.d.mts +1 -1
  67. package/dist/core/predefined/operators/map-result-err.d.mts.map +1 -1
  68. package/dist/core/predefined/operators/map-result-ok.d.mts +1 -1
  69. package/dist/core/predefined/operators/map-result-ok.d.mts.map +1 -1
  70. package/dist/core/predefined/operators/map-to.d.mts +1 -1
  71. package/dist/core/predefined/operators/map-to.d.mts.map +1 -1
  72. package/dist/core/predefined/operators/pluck.d.mts +1 -1
  73. package/dist/core/predefined/operators/pluck.d.mts.map +1 -1
  74. package/dist/core/predefined/operators/skip.d.mts +2 -2
  75. package/dist/core/predefined/operators/skip.d.mts.map +1 -1
  76. package/dist/core/predefined/operators/take.d.mts +2 -2
  77. package/dist/core/predefined/operators/take.d.mts.map +1 -1
  78. package/dist/core/predefined/operators/unwrap-optional.d.mts +1 -1
  79. package/dist/core/predefined/operators/unwrap-optional.d.mts.map +1 -1
  80. package/dist/core/predefined/operators/unwrap-result-err.d.mts +1 -1
  81. package/dist/core/predefined/operators/unwrap-result-err.d.mts.map +1 -1
  82. package/dist/core/predefined/operators/unwrap-result-ok.d.mts +1 -1
  83. package/dist/core/predefined/operators/unwrap-result-ok.d.mts.map +1 -1
  84. package/dist/core/types/id.d.mts +1 -1
  85. package/dist/core/types/id.d.mts.map +1 -1
  86. package/dist/core/types/observable-family.d.mts +3 -3
  87. package/dist/core/types/observable-family.d.mts.map +1 -1
  88. package/dist/core/types/observable-kind.d.mts +1 -1
  89. package/dist/core/types/observable-kind.d.mts.map +1 -1
  90. package/dist/core/types/observable.d.mts +4 -4
  91. package/dist/core/types/observable.d.mts.map +1 -1
  92. package/dist/core/types/types.d.mts +1 -1
  93. package/dist/core/types/types.d.mts.map +1 -1
  94. package/dist/core/utils/id-maker.d.mts +1 -1
  95. package/dist/core/utils/id-maker.d.mts.map +1 -1
  96. package/dist/core/utils/max-depth.d.mts +1 -1
  97. package/dist/core/utils/max-depth.d.mts.map +1 -1
  98. package/dist/core/utils/observable-utils.d.mts +1 -1
  99. package/dist/core/utils/observable-utils.d.mts.map +1 -1
  100. package/dist/core/utils/utils.d.mts +1 -1
  101. package/dist/core/utils/utils.d.mts.map +1 -1
  102. package/dist/utils/collect-to-array.d.mts +1 -1
  103. package/dist/utils/collect-to-array.d.mts.map +1 -1
  104. package/dist/utils/create-boolean-state.d.mts +17 -14
  105. package/dist/utils/create-boolean-state.d.mts.map +1 -1
  106. package/dist/utils/create-boolean-state.mjs +4 -2
  107. package/dist/utils/create-boolean-state.mjs.map +1 -1
  108. package/dist/utils/create-reducer.d.mts +49 -2
  109. package/dist/utils/create-reducer.d.mts.map +1 -1
  110. package/dist/utils/create-reducer.mjs +31 -2
  111. package/dist/utils/create-reducer.mjs.map +1 -1
  112. package/dist/utils/create-state.d.mts +37 -2
  113. package/dist/utils/create-state.d.mts.map +1 -1
  114. package/dist/utils/create-state.mjs +36 -2
  115. package/dist/utils/create-state.mjs.map +1 -1
  116. package/package.json +11 -11
  117. package/src/core/base/create-child-observable.mts +1 -1
  118. package/src/core/base/create-observable-base.mts +131 -44
  119. package/src/core/base/create-root-observable.mts +1 -1
  120. package/src/core/base/observable-base.test.mts +7 -7
  121. package/src/core/combine/combine.mts +10 -10
  122. package/src/core/combine/merge.mts +8 -8
  123. package/src/core/combine/zip.mts +11 -11
  124. package/src/core/create/counter.mts +1 -1
  125. package/src/core/create/from-abortable-promise.mts +1 -1
  126. package/src/core/create/from-promise.mts +1 -1
  127. package/src/core/create/from-subscribable.mts +3 -3
  128. package/src/core/create/just.mts +1 -1
  129. package/src/core/create/source.mts +3 -3
  130. package/src/core/create/timer.mts +1 -1
  131. package/src/core/operators/audit.mts +5 -5
  132. package/src/core/operators/debounce.mts +5 -5
  133. package/src/core/operators/filter.mts +5 -5
  134. package/src/core/operators/map.mts +5 -5
  135. package/src/core/operators/merge-map.mts +5 -5
  136. package/src/core/operators/pairwise.mts +5 -5
  137. package/src/core/operators/scan.mts +4 -4
  138. package/src/core/operators/skip-if-no-change.mts +4 -4
  139. package/src/core/operators/skip-until.mts +4 -4
  140. package/src/core/operators/skip-while.mts +4 -4
  141. package/src/core/operators/switch-map.mts +5 -5
  142. package/src/core/operators/take-until.mts +4 -4
  143. package/src/core/operators/take-while.mts +5 -5
  144. package/src/core/operators/throttle.mts +5 -5
  145. package/src/core/operators/with-buffered-from.mts +4 -4
  146. package/src/core/operators/with-current-value-from.mts +4 -4
  147. package/src/core/operators/with-initial-value.mts +5 -5
  148. package/src/core/predefined/operators/attach-index.mts +2 -2
  149. package/src/core/predefined/operators/map-optional.mts +1 -1
  150. package/src/core/predefined/operators/map-result-err.mts +1 -1
  151. package/src/core/predefined/operators/map-result-ok.mts +1 -1
  152. package/src/core/predefined/operators/map-to.mts +1 -1
  153. package/src/core/predefined/operators/pluck.mts +1 -1
  154. package/src/core/predefined/operators/skip.mts +2 -2
  155. package/src/core/predefined/operators/take.mts +2 -2
  156. package/src/core/predefined/operators/unwrap-optional.mts +2 -2
  157. package/src/core/predefined/operators/unwrap-result-err.mts +2 -2
  158. package/src/core/predefined/operators/unwrap-result-ok.mts +2 -2
  159. package/src/core/types/id.mts +1 -1
  160. package/src/core/types/observable-family.mts +15 -15
  161. package/src/core/types/observable-kind.mts +1 -1
  162. package/src/core/types/observable.mts +4 -4
  163. package/src/core/types/types.mts +1 -1
  164. package/src/core/utils/id-maker.mts +4 -4
  165. package/src/core/utils/max-depth.mts +1 -1
  166. package/src/core/utils/observable-utils.mts +1 -1
  167. package/src/core/utils/utils.mts +1 -1
  168. package/src/utils/collect-to-array.mts +1 -1
  169. package/src/utils/create-boolean-state.mts +18 -14
  170. package/src/utils/create-boolean-state.test.mts +23 -0
  171. package/src/utils/create-reducer.mts +59 -2
  172. package/src/utils/create-reducer.test.mts +87 -0
  173. package/src/utils/create-state.mts +38 -2
  174. package/src/utils/create-state.test.mts +72 -0
@@ -1,8 +1,8 @@
1
1
  import { Optional, Result } from 'ts-data-forge';
2
2
  import { createRootObservable } from '../base/index.mjs';
3
- import {
4
- type FromSubscribableObservable,
5
- type Subscribable,
3
+ import type {
4
+ FromSubscribableObservable,
5
+ Subscribable,
6
6
  } from '../types/index.mjs';
7
7
 
8
8
  /**
@@ -1,6 +1,6 @@
1
1
  import { Optional } from 'ts-data-forge';
2
2
  import { createRootObservable } from '../base/index.mjs';
3
- import { type InitializedRootObservable } from '../types/index.mjs';
3
+ import type { InitializedRootObservable } from '../types/index.mjs';
4
4
 
5
5
  /**
6
6
  * Creates an Observable that holds a single static value and immediately
@@ -1,8 +1,8 @@
1
1
  import { Arr, Optional } from 'ts-data-forge';
2
2
  import { createRootObservable } from '../base/index.mjs';
3
- import {
4
- type InitializedSourceObservable,
5
- type SourceObservable,
3
+ import type {
4
+ InitializedSourceObservable,
5
+ SourceObservable,
6
6
  } from '../types/index.mjs';
7
7
 
8
8
  /**
@@ -1,6 +1,6 @@
1
1
  import { Optional } from 'ts-data-forge';
2
2
  import { createRootObservable } from '../base/index.mjs';
3
- import { type TimerId, type TimerObservable } from '../types/index.mjs';
3
+ import type { TimerId, TimerObservable } from '../types/index.mjs';
4
4
 
5
5
  /**
6
6
  * Creates an observable that emits 0 after a specified delay and then completes.
@@ -1,10 +1,10 @@
1
1
  import { Optional } from 'ts-data-forge';
2
2
  import { createAsyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type AuditOperatorObservable,
5
- type KeepInitialValueOperator,
6
- type Observable,
7
- type TimerId,
3
+ import type {
4
+ AuditOperatorObservable,
5
+ KeepInitialValueOperator,
6
+ Observable,
7
+ TimerId,
8
8
  } from '../types/index.mjs';
9
9
 
10
10
  /**
@@ -1,10 +1,10 @@
1
1
  import { Optional } from 'ts-data-forge';
2
2
  import { createAsyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type DebounceOperatorObservable,
5
- type KeepInitialValueOperator,
6
- type Observable,
7
- type TimerId,
3
+ import type {
4
+ DebounceOperatorObservable,
5
+ KeepInitialValueOperator,
6
+ Observable,
7
+ TimerId,
8
8
  } from '../types/index.mjs';
9
9
 
10
10
  /**
@@ -7,11 +7,11 @@ import {
7
7
  } from 'ts-data-forge';
8
8
  import { createSyncChildObservable } from '../base/index.mjs';
9
9
  import { source } from '../create/index.mjs';
10
- import {
11
- type DropInitialValueOperator,
12
- type FilterOperatorObservable,
13
- type InitializedObservable,
14
- type Observable,
10
+ import type {
11
+ DropInitialValueOperator,
12
+ FilterOperatorObservable,
13
+ InitializedObservable,
14
+ Observable,
15
15
  } from '../types/index.mjs';
16
16
  import { withInitialValue } from './with-initial-value.mjs';
17
17
 
@@ -1,11 +1,11 @@
1
1
  import { Optional, SafeUint, asSafeUint, expectType } from 'ts-data-forge';
2
2
  import { createSyncChildObservable } from '../base/index.mjs';
3
3
  import { source } from '../create/index.mjs';
4
- import {
5
- type InitializedObservable,
6
- type KeepInitialValueOperator,
7
- type MapOperatorObservable,
8
- type Observable,
4
+ import type {
5
+ InitializedObservable,
6
+ KeepInitialValueOperator,
7
+ MapOperatorObservable,
8
+ Observable,
9
9
  } from '../types/index.mjs';
10
10
  import { withInitialValue } from './with-initial-value.mjs';
11
11
 
@@ -1,10 +1,10 @@
1
1
  import { Arr, Optional } from 'ts-data-forge';
2
2
  import { createAsyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type DropInitialValueOperator,
5
- type MergeMapOperatorObservable,
6
- type Observable,
7
- type Subscription,
3
+ import type {
4
+ DropInitialValueOperator,
5
+ MergeMapOperatorObservable,
6
+ Observable,
7
+ Subscription,
8
8
  } from '../types/index.mjs';
9
9
 
10
10
  /**
@@ -1,10 +1,10 @@
1
1
  import { Optional } from 'ts-data-forge';
2
- import { type FixedLengthTuple } from 'ts-type-forge';
2
+ import type { FixedLengthTuple } from 'ts-type-forge';
3
3
  import { createSyncChildObservable } from '../base/index.mjs';
4
- import {
5
- type DropInitialValueOperator,
6
- type Observable,
7
- type PairwiseOperatorObservable,
4
+ import type {
5
+ DropInitialValueOperator,
6
+ Observable,
7
+ PairwiseOperatorObservable,
8
8
  } from '../types/index.mjs';
9
9
 
10
10
  /**
@@ -1,9 +1,9 @@
1
1
  import { Optional } from 'ts-data-forge';
2
2
  import { createInitializedSyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type Observable,
5
- type ScanOperatorObservable,
6
- type WithInitialValueOperator,
3
+ import type {
4
+ Observable,
5
+ ScanOperatorObservable,
6
+ WithInitialValueOperator,
7
7
  } from '../types/index.mjs';
8
8
 
9
9
  /**
@@ -1,9 +1,9 @@
1
1
  import { Optional } from 'ts-data-forge';
2
2
  import { createSyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type KeepInitialValueOperator,
5
- type Observable,
6
- type SkipIfNoChangeOperatorObservable,
3
+ import type {
4
+ KeepInitialValueOperator,
5
+ Observable,
6
+ SkipIfNoChangeOperatorObservable,
7
7
  } from '../types/index.mjs';
8
8
 
9
9
  /**
@@ -1,9 +1,9 @@
1
1
  import { Optional } from 'ts-data-forge';
2
2
  import { createSyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type DropInitialValueOperator,
5
- type Observable,
6
- type SkipUntilOperatorObservable,
3
+ import type {
4
+ DropInitialValueOperator,
5
+ Observable,
6
+ SkipUntilOperatorObservable,
7
7
  } from '../types/index.mjs';
8
8
 
9
9
  /**
@@ -1,9 +1,9 @@
1
1
  import { Optional, SafeUint, asSafeUint, pipe } from 'ts-data-forge';
2
2
  import { createSyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type DropInitialValueOperator,
5
- type Observable,
6
- type SkipWhileOperatorObservable,
3
+ import type {
4
+ DropInitialValueOperator,
5
+ Observable,
6
+ SkipWhileOperatorObservable,
7
7
  } from '../types/index.mjs';
8
8
 
9
9
  /**
@@ -1,10 +1,10 @@
1
1
  import { Optional } from 'ts-data-forge';
2
2
  import { createAsyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type DropInitialValueOperator,
5
- type Observable,
6
- type Subscription,
7
- type SwitchMapOperatorObservable,
3
+ import type {
4
+ DropInitialValueOperator,
5
+ Observable,
6
+ Subscription,
7
+ SwitchMapOperatorObservable,
8
8
  } from '../types/index.mjs';
9
9
 
10
10
  /**
@@ -1,9 +1,9 @@
1
1
  import { Optional } from 'ts-data-forge';
2
2
  import { createSyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type KeepInitialValueOperator,
5
- type Observable,
6
- type TakeUntilOperatorObservable,
3
+ import type {
4
+ KeepInitialValueOperator,
5
+ Observable,
6
+ TakeUntilOperatorObservable,
7
7
  } from '../types/index.mjs';
8
8
 
9
9
  /**
@@ -7,11 +7,11 @@ import {
7
7
  } from 'ts-data-forge';
8
8
  import { createSyncChildObservable } from '../base/index.mjs';
9
9
  import { source } from '../create/index.mjs';
10
- import {
11
- type DropInitialValueOperator,
12
- type InitializedObservable,
13
- type Observable,
14
- type TakeWhileOperatorObservable,
10
+ import type {
11
+ DropInitialValueOperator,
12
+ InitializedObservable,
13
+ Observable,
14
+ TakeWhileOperatorObservable,
15
15
  } from '../types/index.mjs';
16
16
  import { withInitialValue } from './with-initial-value.mjs';
17
17
 
@@ -1,10 +1,10 @@
1
1
  import { Optional } from 'ts-data-forge';
2
2
  import { createSyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type KeepInitialValueOperator,
5
- type Observable,
6
- type ThrottleOperatorObservable,
7
- type TimerId,
3
+ import type {
4
+ KeepInitialValueOperator,
5
+ Observable,
6
+ ThrottleOperatorObservable,
7
+ TimerId,
8
8
  } from '../types/index.mjs';
9
9
 
10
10
  /**
@@ -1,9 +1,9 @@
1
1
  import { Arr, Optional, pipe } from 'ts-data-forge';
2
2
  import { createSyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type KeepInitialValueOperator,
5
- type Observable,
6
- type WithBufferedFromOperatorObservable,
3
+ import type {
4
+ KeepInitialValueOperator,
5
+ Observable,
6
+ WithBufferedFromOperatorObservable,
7
7
  } from '../types/index.mjs';
8
8
  import { maxDepth } from '../utils/index.mjs';
9
9
 
@@ -1,9 +1,9 @@
1
1
  import { Optional, pipe } from 'ts-data-forge';
2
2
  import { createSyncChildObservable } from '../base/index.mjs';
3
- import {
4
- type DropInitialValueOperator,
5
- type Observable,
6
- type WithCurrentValueFromOperatorObservable,
3
+ import type {
4
+ DropInitialValueOperator,
5
+ Observable,
6
+ WithCurrentValueFromOperatorObservable,
7
7
  } from '../types/index.mjs';
8
8
  import { maxDepth } from '../utils/index.mjs';
9
9
 
@@ -1,11 +1,11 @@
1
1
  import { expectType, Optional } from 'ts-data-forge';
2
2
  import { createInitializedSyncChildObservable } from '../base/index.mjs';
3
3
  import { source } from '../create/index.mjs';
4
- import {
5
- type InitializedObservable,
6
- type Observable,
7
- type WithInitialValueOperator,
8
- type WithInitialValueOperatorObservable,
4
+ import type {
5
+ InitializedObservable,
6
+ Observable,
7
+ WithInitialValueOperator,
8
+ WithInitialValueOperatorObservable,
9
9
  } from '../types/index.mjs';
10
10
 
11
11
  /**
@@ -1,6 +1,6 @@
1
- import { type SafeUint } from 'ts-type-forge';
1
+ import type { SafeUint } from 'ts-type-forge';
2
2
  import { map } from '../../operators/index.mjs';
3
- import { type KeepInitialValueOperator } from '../../types/index.mjs';
3
+ import type { KeepInitialValueOperator } from '../../types/index.mjs';
4
4
 
5
5
  /**
6
6
  * Attaches a sequential index to each emitted value, producing `[index, value]` tuples.
@@ -1,6 +1,6 @@
1
1
  import { Optional, type UnknownOptional } from 'ts-data-forge';
2
2
  import { map } from '../../operators/index.mjs';
3
- import { type KeepInitialValueOperator } from '../../types/index.mjs';
3
+ import type { KeepInitialValueOperator } from '../../types/index.mjs';
4
4
 
5
5
  /**
6
6
  * Transforms the inner value of an `Optional` type emitted by the source.
@@ -1,6 +1,6 @@
1
1
  import { Result, type UnknownResult } from 'ts-data-forge';
2
2
  import { map } from '../../operators/index.mjs';
3
- import { type KeepInitialValueOperator } from '../../types/index.mjs';
3
+ import type { KeepInitialValueOperator } from '../../types/index.mjs';
4
4
 
5
5
  /**
6
6
  * Transforms the error value (`Err`) of a `Result` type emitted by the source.
@@ -1,6 +1,6 @@
1
1
  import { Result, type UnknownResult } from 'ts-data-forge';
2
2
  import { map } from '../../operators/index.mjs';
3
- import { type KeepInitialValueOperator } from '../../types/index.mjs';
3
+ import type { KeepInitialValueOperator } from '../../types/index.mjs';
4
4
 
5
5
  /**
6
6
  * Transforms the success value (`Ok`) of a `Result` type emitted by the source.
@@ -1,5 +1,5 @@
1
1
  import { map } from '../../operators/index.mjs';
2
- import { type KeepInitialValueOperator } from '../../types/index.mjs';
2
+ import type { KeepInitialValueOperator } from '../../types/index.mjs';
3
3
 
4
4
  /**
5
5
  * Maps all emitted values to a constant value, ignoring the source values.
@@ -1,5 +1,5 @@
1
1
  import { map } from '../../operators/index.mjs';
2
- import { type KeepInitialValueOperator } from '../../types/index.mjs';
2
+ import type { KeepInitialValueOperator } from '../../types/index.mjs';
3
3
 
4
4
  /**
5
5
  * Extracts a property value from each emitted object by key.
@@ -1,7 +1,7 @@
1
1
  import { PositiveSafeInt } from 'ts-data-forge';
2
- import { type PositiveSafeIntWithSmallInt } from 'ts-type-forge';
2
+ import type { PositiveSafeIntWithSmallInt } from 'ts-type-forge';
3
3
  import { skipWhile } from '../../operators/index.mjs';
4
- import { type DropInitialValueOperator } from '../../types/index.mjs';
4
+ import type { DropInitialValueOperator } from '../../types/index.mjs';
5
5
 
6
6
  /**
7
7
  * Skips the first `n` emissions from the source observable.
@@ -1,6 +1,6 @@
1
- import { type PositiveSafeIntWithSmallInt } from 'ts-type-forge';
1
+ import type { PositiveSafeIntWithSmallInt } from 'ts-type-forge';
2
2
  import { takeWhile } from '../../operators/index.mjs';
3
- import { type DropInitialValueOperator } from '../../types/index.mjs';
3
+ import type { DropInitialValueOperator } from '../../types/index.mjs';
4
4
 
5
5
  /**
6
6
  * Takes only the first `n` emissions from the source observable, then completes.
@@ -1,7 +1,7 @@
1
1
  import { Optional, type UnknownOptional } from 'ts-data-forge';
2
- import { type Fn } from 'ts-type-forge';
2
+ import type { Fn } from 'ts-type-forge';
3
3
  import { map } from '../../operators/index.mjs';
4
- import { type KeepInitialValueOperator } from '../../types/index.mjs';
4
+ import type { KeepInitialValueOperator } from '../../types/index.mjs';
5
5
 
6
6
  /**
7
7
  * Unwraps `Optional` values, converting `Some(value)` to `value` and `None` to `undefined`.
@@ -1,7 +1,7 @@
1
1
  import { Result, type UnknownResult } from 'ts-data-forge';
2
- import { type Fn } from 'ts-type-forge';
2
+ import type { Fn } from 'ts-type-forge';
3
3
  import { map } from '../../operators/index.mjs';
4
- import { type KeepInitialValueOperator } from '../../types/index.mjs';
4
+ import type { KeepInitialValueOperator } from '../../types/index.mjs';
5
5
 
6
6
  /**
7
7
  * Unwraps the error value from a `Result`, converting `Err(error)` to `error` and `Ok` to `undefined`.
@@ -1,7 +1,7 @@
1
1
  import { Result, type UnknownResult } from 'ts-data-forge';
2
- import { type Fn } from 'ts-type-forge';
2
+ import type { Fn } from 'ts-type-forge';
3
3
  import { map } from '../../operators/index.mjs';
4
- import { type KeepInitialValueOperator } from '../../types/index.mjs';
4
+ import type { KeepInitialValueOperator } from '../../types/index.mjs';
5
5
 
6
6
  /**
7
7
  * Unwraps the success value from a `Result`, converting `Ok(value)` to `value` and `Err` to `undefined`.
@@ -1,4 +1,4 @@
1
- import { type Brand } from 'ts-type-forge';
1
+ import type { Brand } from 'ts-type-forge';
2
2
 
3
3
  export type ObservableId = Brand<symbol, 'observable-id'>;
4
4
 
@@ -1,21 +1,21 @@
1
1
  import { expectType, type Result } from 'ts-data-forge';
2
- import {
3
- type ArrayElement,
4
- type FixedLengthTuple,
5
- type NonEmptyTuple,
6
- type SafeUint,
2
+ import type {
3
+ ArrayElement,
4
+ FixedLengthTuple,
5
+ NonEmptyTuple,
6
+ SafeUint,
7
7
  } from 'ts-type-forge';
8
- import {
9
- type AsyncChildObservable,
10
- type InitializedObservable,
11
- type InitializedRootObservable,
12
- type InitializedSyncChildObservable,
13
- type Observable,
14
- type RootObservable,
15
- type SyncChildObservable,
16
- type Unwrap,
8
+ import type {
9
+ AsyncChildObservable,
10
+ InitializedObservable,
11
+ InitializedRootObservable,
12
+ InitializedSyncChildObservable,
13
+ Observable,
14
+ RootObservable,
15
+ SyncChildObservable,
16
+ Unwrap,
17
17
  } from './observable.mjs';
18
- import { type NonEmptyUnknownList } from './types.mjs';
18
+ import type { NonEmptyUnknownList } from './types.mjs';
19
19
 
20
20
  // RootObservable
21
21
 
@@ -1,4 +1,4 @@
1
- import { type StrictExclude } from 'ts-type-forge';
1
+ import type { StrictExclude } from 'ts-type-forge';
2
2
 
3
3
  export type ObservableKind = 'root' | 'sync child' | 'async child';
4
4
 
@@ -1,8 +1,8 @@
1
1
  import { expectType, type Optional, type Some } from 'ts-data-forge';
2
- import { type FixedLengthTuple, type StrictOmit } from 'ts-type-forge';
3
- import { type ObservableId, type UpdateToken } from './id.mjs';
4
- import { type ObservableKind } from './observable-kind.mjs';
5
- import { type NonEmptyUnknownList, type Subscription } from './types.mjs';
2
+ import type { FixedLengthTuple, StrictOmit } from 'ts-type-forge';
3
+ import type { ObservableId, UpdateToken } from './id.mjs';
4
+ import type { ObservableKind } from './observable-kind.mjs';
5
+ import type { NonEmptyUnknownList, Subscription } from './types.mjs';
6
6
 
7
7
  /**
8
8
  * Inheritance
@@ -1,5 +1,5 @@
1
1
  import { expectType, type Queue } from 'ts-data-forge';
2
- import { type NonEmptyTuple } from 'ts-type-forge';
2
+ import type { NonEmptyTuple } from 'ts-type-forge';
3
3
 
4
4
  export type TupleToQueueTuple<T extends readonly unknown[]> = Readonly<{
5
5
  [P in keyof T]: Queue<T[P]>;
@@ -1,7 +1,7 @@
1
- import {
2
- type ObservableId,
3
- type SubscriberId,
4
- type UpdateToken,
1
+ import type {
2
+ ObservableId,
3
+ SubscriberId,
4
+ UpdateToken,
5
5
  } from '../types/index.mjs';
6
6
 
7
7
  function* idMaker<T extends symbol>(): Generator<T, T, T> {
@@ -1,5 +1,5 @@
1
1
  import { Arr, Optional, pipe } from 'ts-data-forge';
2
- import { type Observable } from '../types/index.mjs';
2
+ import type { Observable } from '../types/index.mjs';
3
3
 
4
4
  export const maxDepth = (parents: readonly Observable<unknown>[]): number =>
5
5
  pipe(Arr.maxBy(parents, (p) => p.depth))
@@ -1,4 +1,4 @@
1
- import { type Subscriber } from '../types/index.mjs';
1
+ import type { Subscriber } from '../types/index.mjs';
2
2
 
3
3
  export const toSubscriber = <A,>(
4
4
  onNext: (v: A) => void,
@@ -1,5 +1,5 @@
1
1
  import { Arr, asSafeInt, asUint32, SafeInt } from 'ts-data-forge';
2
- import { type NegativeInt32, type Uint32 } from 'ts-type-forge';
2
+ import type { NegativeInt32, Uint32 } from 'ts-type-forge';
3
3
 
4
4
  export const halfInt = (x: SafeInt): SafeInt =>
5
5
  x % 2 === 0
@@ -1,4 +1,4 @@
1
- import { type Observable } from '../core/index.mjs';
1
+ import type { Observable } from '../core/index.mjs';
2
2
 
3
3
  export const collectToArray = <A,>(
4
4
  observable: Observable<A>,
@@ -1,4 +1,5 @@
1
- import { type InitializedObservable } from '../core/index.mjs';
1
+ import type { InitializedObservable } from '../core/index.mjs';
2
+ import type { StateOptions } from './create-reducer.mjs';
2
3
  import { createState } from './create-state.mjs';
3
4
 
4
5
  /**
@@ -6,6 +7,8 @@ import { createState } from './create-state.mjs';
6
7
  * Extends `createState` with boolean-specific helpers like `toggle`, `setTrue`, and `setFalse`.
7
8
  *
8
9
  * @param initialState - The initial boolean value
10
+ * @param options - {@link StateOptions}: `equals`, to pass on only the
11
+ * updates that change the state
9
12
  * @returns A 2-element tuple: `[state, { setTrue, setFalse, toggle, setState, updateState, resetState, getSnapshot, initialState }]`
10
13
  *
11
14
  * @example
@@ -14,24 +17,25 @@ import { createState } from './create-state.mjs';
14
17
  * import { createBooleanState } from 'synstate';
15
18
  * import { useObservableValue } from 'synstate-react-hooks';
16
19
  *
17
- * // Menu drawer open/close state.
18
- * // setTrue and setFalse can be passed directly as callbacks
19
- * // — no need to create wrapper functions like `() => setState(true)`.
20
- * const [menuOpen$, { setTrue: openMenu, setFalse: closeMenu }] =
21
- * createBooleanState(false);
20
+ * // Menu drawer open/close state.
21
+ * // setTrue and setFalse can be passed directly as callbacks
22
+ * // — no need to create wrapper functions like `() => setState(true)`.
23
+ * const [menuOpen$, { setTrue: openMenu, setFalse: closeMenu }] =
24
+ * createBooleanState(false);
22
25
  *
23
- * const SampleComponent = (): React.JSX.Element => (
24
- * <MenuDrawer
25
- * open={useObservableValue(menuOpen$)}
26
- * onClose={closeMenu}
27
- * onOpen={openMenu}
28
- * />
29
- * );
26
+ * const SampleComponent = (): React.JSX.Element => (
27
+ * <MenuDrawer
28
+ * open={useObservableValue(menuOpen$)}
29
+ * onClose={closeMenu}
30
+ * onOpen={openMenu}
31
+ * />
32
+ * );
30
33
  * ```
31
34
  */
32
35
 
33
36
  export const createBooleanState = (
34
37
  initialState: boolean,
38
+ options?: StateOptions<boolean>,
35
39
  ): readonly [
36
40
  state: InitializedObservable<boolean>,
37
41
  utils: Readonly<{
@@ -46,7 +50,7 @@ export const createBooleanState = (
46
50
  }>,
47
51
  ] => {
48
52
  const [state, setState, { updateState, resetState, getSnapshot }] =
49
- createState(initialState);
53
+ createState(initialState, options);
50
54
 
51
55
  return [
52
56
  state,
@@ -0,0 +1,23 @@
1
+ import { createBooleanState } from './create-boolean-state.mjs';
2
+
3
+ describe(createBooleanState, () => {
4
+ test('with `equals`, setting what it already holds passes nothing on', () => {
5
+ const [state, { setTrue, setFalse }] = createBooleanState(false, {
6
+ equals: Object.is,
7
+ });
8
+
9
+ const mut_seen: boolean[] = [];
10
+
11
+ state.subscribe((value) => {
12
+ mut_seen.push(value);
13
+ });
14
+
15
+ setFalse();
16
+
17
+ setTrue();
18
+
19
+ setTrue();
20
+
21
+ assert.deepStrictEqual(mut_seen, [false, true]);
22
+ });
23
+ });