@typed/fx 1.18.4 → 1.20.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.
- package/AsyncData/package.json +6 -0
- package/Emitter/package.json +6 -0
- package/Form/package.json +6 -0
- package/FormEntry/package.json +6 -0
- package/Fx/package.json +6 -0
- package/Guard/package.json +6 -0
- package/Idle/package.json +6 -0
- package/Match/package.json +6 -0
- package/Pull/package.json +6 -0
- package/Push/package.json +6 -0
- package/RefArray/package.json +6 -0
- package/RefChunk/package.json +6 -0
- package/RefHashMap/package.json +6 -0
- package/RefHashSet/package.json +6 -0
- package/RefSubject/package.json +6 -0
- package/Sink/package.json +6 -0
- package/Stream/package.json +6 -0
- package/Subject/package.json +6 -0
- package/TypeId/package.json +6 -0
- package/Typeclass/package.json +6 -0
- package/Versioned/package.json +6 -0
- package/dist/cjs/AsyncData.js +177 -0
- package/dist/cjs/AsyncData.js.map +1 -0
- package/dist/cjs/Emitter.js +24 -21
- package/dist/cjs/Emitter.js.map +1 -1
- package/dist/cjs/Form.js +78 -21
- package/dist/cjs/Form.js.map +1 -1
- package/dist/cjs/FormEntry.js +75 -48
- package/dist/cjs/FormEntry.js.map +1 -1
- package/dist/cjs/Fx.js +517 -872
- package/dist/cjs/Fx.js.map +1 -1
- package/dist/cjs/Guard.js +21 -13
- package/dist/cjs/Guard.js.map +1 -1
- package/dist/cjs/Idle.js +49 -37
- package/dist/cjs/Idle.js.map +1 -1
- package/dist/cjs/Match.js +99 -61
- package/dist/cjs/Match.js.map +1 -1
- package/dist/cjs/Pull.js.map +1 -1
- package/dist/cjs/Push.js +168 -0
- package/dist/cjs/Push.js.map +1 -0
- package/dist/cjs/RefArray.js +32 -30
- package/dist/cjs/RefArray.js.map +1 -1
- package/dist/cjs/RefChunk.js +26 -24
- package/dist/cjs/RefChunk.js.map +1 -1
- package/dist/cjs/RefHashMap.js +20 -20
- package/dist/cjs/RefHashMap.js.map +1 -1
- package/dist/cjs/RefHashSet.js +11 -8
- package/dist/cjs/RefHashSet.js.map +1 -1
- package/dist/cjs/RefSubject.js +899 -158
- package/dist/cjs/RefSubject.js.map +1 -1
- package/dist/cjs/Sink.js +588 -62
- package/dist/cjs/Sink.js.map +1 -1
- package/dist/cjs/Stream.js +15 -10
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/Subject.js +153 -55
- package/dist/cjs/Subject.js.map +1 -1
- package/dist/cjs/TypeId.js +10 -5
- package/dist/cjs/TypeId.js.map +1 -1
- package/dist/cjs/Typeclass.js +28 -31
- package/dist/cjs/Typeclass.js.map +1 -1
- package/dist/cjs/Versioned.js +118 -57
- package/dist/cjs/Versioned.js.map +1 -1
- package/dist/cjs/index.js +44 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/{deferred-ref.js → DeferredRef.js} +45 -13
- package/dist/cjs/internal/DeferredRef.js.map +1 -0
- package/dist/cjs/internal/UnionToTuple.js +6 -0
- package/dist/cjs/internal/UnionToTuple.js.map +1 -0
- package/dist/cjs/internal/core.js +1590 -779
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/diff.js +114 -0
- package/dist/cjs/internal/diff.js.map +1 -0
- package/dist/cjs/internal/effect-loop-operator.js +288 -0
- package/dist/cjs/internal/effect-loop-operator.js.map +1 -0
- package/dist/cjs/internal/effect-operator.js +46 -37
- package/dist/cjs/internal/effect-operator.js.map +1 -1
- package/dist/cjs/internal/effect-producer.js +74 -0
- package/dist/cjs/internal/effect-producer.js.map +1 -0
- package/dist/cjs/internal/helpers.js +158 -128
- package/dist/cjs/internal/helpers.js.map +1 -1
- package/dist/cjs/internal/keyed.js +136 -173
- package/dist/cjs/internal/keyed.js.map +1 -1
- package/dist/cjs/internal/loop-operator.js +213 -0
- package/dist/cjs/internal/loop-operator.js.map +1 -0
- package/dist/cjs/internal/operator.js +79 -0
- package/dist/cjs/internal/operator.js.map +1 -0
- package/dist/cjs/internal/protos.js +19 -81
- package/dist/cjs/internal/protos.js.map +1 -1
- package/dist/cjs/internal/provide.js +47 -25
- package/dist/cjs/internal/provide.js.map +1 -1
- package/dist/cjs/internal/requestIdleCallback.js +5 -5
- package/dist/cjs/internal/requestIdleCallback.js.map +1 -1
- package/dist/cjs/internal/share.js +12 -15
- package/dist/cjs/internal/share.js.map +1 -1
- package/dist/cjs/internal/sync-operator.js +50 -22
- package/dist/cjs/internal/sync-operator.js.map +1 -1
- package/dist/cjs/internal/sync-producer.js +114 -0
- package/dist/cjs/internal/sync-producer.js.map +1 -0
- package/dist/cjs/internal/withKey.js +45 -51
- package/dist/cjs/internal/withKey.js.map +1 -1
- package/dist/dts/AsyncData.d.ts +185 -0
- package/dist/dts/AsyncData.d.ts.map +1 -0
- package/dist/dts/Emitter.d.ts +13 -20
- package/dist/dts/Emitter.d.ts.map +1 -1
- package/dist/dts/Form.d.ts +45 -28
- package/dist/dts/Form.d.ts.map +1 -1
- package/dist/dts/FormEntry.d.ts +25 -13
- package/dist/dts/FormEntry.d.ts.map +1 -1
- package/dist/dts/Fx.d.ts +983 -1387
- package/dist/dts/Fx.d.ts.map +1 -1
- package/dist/dts/Guard.d.ts +8 -1
- package/dist/dts/Guard.d.ts.map +1 -1
- package/dist/dts/Idle.d.ts +3 -3
- package/dist/dts/Idle.d.ts.map +1 -1
- package/dist/dts/Match.d.ts +8 -8
- package/dist/dts/Match.d.ts.map +1 -1
- package/dist/dts/Pull.d.ts +5 -5
- package/dist/dts/Pull.d.ts.map +1 -1
- package/dist/dts/Push.d.ts +170 -0
- package/dist/dts/Push.d.ts.map +1 -0
- package/dist/dts/RefArray.d.ts +21 -23
- package/dist/dts/RefArray.d.ts.map +1 -1
- package/dist/dts/RefChunk.d.ts +17 -19
- package/dist/dts/RefChunk.d.ts.map +1 -1
- package/dist/dts/RefHashMap.d.ts +19 -20
- package/dist/dts/RefHashMap.d.ts.map +1 -1
- package/dist/dts/RefHashSet.d.ts +12 -16
- package/dist/dts/RefHashSet.d.ts.map +1 -1
- package/dist/dts/RefSubject.d.ts +396 -187
- package/dist/dts/RefSubject.d.ts.map +1 -1
- package/dist/dts/Sink.d.ts +193 -93
- package/dist/dts/Sink.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +7 -1
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/Subject.d.ts +27 -36
- package/dist/dts/Subject.d.ts.map +1 -1
- package/dist/dts/TypeId.d.ts +10 -0
- package/dist/dts/TypeId.d.ts.map +1 -1
- package/dist/dts/Typeclass.d.ts +2 -2
- package/dist/dts/Typeclass.d.ts.map +1 -1
- package/dist/dts/Versioned.d.ts +50 -78
- package/dist/dts/Versioned.d.ts.map +1 -1
- package/dist/dts/index.d.ts +66 -6
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/DeferredRef.d.ts +20 -0
- package/dist/dts/internal/DeferredRef.d.ts.map +1 -0
- package/dist/dts/internal/UnionToTuple.d.ts +6 -0
- package/dist/dts/internal/UnionToTuple.d.ts.map +1 -0
- package/dist/dts/internal/core.d.ts +218 -450
- package/dist/dts/internal/core.d.ts.map +1 -1
- package/dist/dts/internal/diff.d.ts +38 -0
- package/dist/dts/internal/diff.d.ts.map +1 -0
- package/dist/dts/internal/effect-loop-operator.d.ts +34 -0
- package/dist/dts/internal/effect-loop-operator.d.ts.map +1 -0
- package/dist/dts/internal/effect-operator.d.ts +8 -5
- package/dist/dts/internal/effect-operator.d.ts.map +1 -1
- package/dist/dts/internal/effect-producer.d.ts +25 -0
- package/dist/dts/internal/effect-producer.d.ts.map +1 -0
- package/dist/dts/internal/helpers.d.ts +33 -24
- package/dist/dts/internal/helpers.d.ts.map +1 -1
- package/dist/dts/internal/keyed.d.ts +3 -3
- package/dist/dts/internal/keyed.d.ts.map +1 -1
- package/dist/dts/internal/loop-operator.d.ts +40 -0
- package/dist/dts/internal/loop-operator.d.ts.map +1 -0
- package/dist/dts/internal/operator.d.ts +16 -0
- package/dist/dts/internal/operator.d.ts.map +1 -0
- package/dist/dts/internal/protos.d.ts +16 -43
- package/dist/dts/internal/protos.d.ts.map +1 -1
- package/dist/dts/internal/provide.d.ts +7 -1
- package/dist/dts/internal/provide.d.ts.map +1 -1
- package/dist/dts/internal/share.d.ts +12 -9
- package/dist/dts/internal/share.d.ts.map +1 -1
- package/dist/dts/internal/sync-operator.d.ts +7 -3
- package/dist/dts/internal/sync-operator.d.ts.map +1 -1
- package/dist/dts/internal/sync-producer.d.ts +36 -0
- package/dist/dts/internal/sync-producer.d.ts.map +1 -0
- package/dist/dts/internal/withKey.d.ts +3 -3
- package/dist/dts/internal/withKey.d.ts.map +1 -1
- package/dist/esm/AsyncData.js +151 -0
- package/dist/esm/AsyncData.js.map +1 -0
- package/dist/esm/Emitter.js +24 -21
- package/dist/esm/Emitter.js.map +1 -1
- package/dist/esm/Form.js +69 -14
- package/dist/esm/Form.js.map +1 -1
- package/dist/esm/FormEntry.js +77 -52
- package/dist/esm/FormEntry.js.map +1 -1
- package/dist/esm/Fx.js +509 -874
- package/dist/esm/Fx.js.map +1 -1
- package/dist/esm/Guard.js +5 -1
- package/dist/esm/Guard.js.map +1 -1
- package/dist/esm/Idle.js +49 -39
- package/dist/esm/Idle.js.map +1 -1
- package/dist/esm/Match.js +103 -63
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Pull.js.map +1 -1
- package/dist/esm/Push.js +159 -0
- package/dist/esm/Push.js.map +1 -0
- package/dist/esm/RefArray.js +32 -30
- package/dist/esm/RefArray.js.map +1 -1
- package/dist/esm/RefChunk.js +26 -24
- package/dist/esm/RefChunk.js.map +1 -1
- package/dist/esm/RefHashMap.js +20 -20
- package/dist/esm/RefHashMap.js.map +1 -1
- package/dist/esm/RefHashSet.js +11 -8
- package/dist/esm/RefHashSet.js.map +1 -1
- package/dist/esm/RefSubject.js +873 -150
- package/dist/esm/RefSubject.js.map +1 -1
- package/dist/esm/Sink.js +608 -57
- package/dist/esm/Sink.js.map +1 -1
- package/dist/esm/Stream.js +13 -9
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/Subject.js +151 -56
- package/dist/esm/Subject.js.map +1 -1
- package/dist/esm/TypeId.js +9 -4
- package/dist/esm/TypeId.js.map +1 -1
- package/dist/esm/Typeclass.js +29 -29
- package/dist/esm/Typeclass.js.map +1 -1
- package/dist/esm/Versioned.js +110 -53
- package/dist/esm/Versioned.js.map +1 -1
- package/dist/esm/index.js +66 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/DeferredRef.js +54 -0
- package/dist/esm/internal/DeferredRef.js.map +1 -0
- package/dist/esm/internal/UnionToTuple.js +2 -0
- package/dist/esm/internal/UnionToTuple.js.map +1 -0
- package/dist/esm/internal/core.js +1439 -719
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/diff.js +82 -0
- package/dist/esm/internal/diff.js.map +1 -0
- package/dist/esm/internal/effect-loop-operator.js +269 -0
- package/dist/esm/internal/effect-loop-operator.js.map +1 -0
- package/dist/esm/internal/effect-operator.js +44 -37
- package/dist/esm/internal/effect-operator.js.map +1 -1
- package/dist/esm/internal/effect-producer.js +47 -0
- package/dist/esm/internal/effect-producer.js.map +1 -0
- package/dist/esm/internal/helpers.js +157 -129
- package/dist/esm/internal/helpers.js.map +1 -1
- package/dist/esm/internal/keyed.js +128 -139
- package/dist/esm/internal/keyed.js.map +1 -1
- package/dist/esm/internal/loop-operator.js +186 -0
- package/dist/esm/internal/loop-operator.js.map +1 -0
- package/dist/esm/internal/operator.js +68 -0
- package/dist/esm/internal/operator.js.map +1 -0
- package/dist/esm/internal/protos.js +16 -75
- package/dist/esm/internal/protos.js.map +1 -1
- package/dist/esm/internal/provide.js +33 -25
- package/dist/esm/internal/provide.js.map +1 -1
- package/dist/esm/internal/requestIdleCallback.js +5 -5
- package/dist/esm/internal/requestIdleCallback.js.map +1 -1
- package/dist/esm/internal/share.js +12 -12
- package/dist/esm/internal/share.js.map +1 -1
- package/dist/esm/internal/sync-operator.js +49 -21
- package/dist/esm/internal/sync-operator.js.map +1 -1
- package/dist/esm/internal/sync-producer.js +88 -0
- package/dist/esm/internal/sync-producer.js.map +1 -0
- package/dist/esm/internal/withKey.js +46 -47
- package/dist/esm/internal/withKey.js.map +1 -1
- package/package.json +22 -62
- package/src/AsyncData.ts +447 -0
- package/src/Emitter.ts +47 -38
- package/src/Form.ts +185 -65
- package/src/FormEntry.ts +142 -109
- package/src/Fx.ts +1685 -1851
- package/src/Guard.ts +12 -1
- package/src/Idle.ts +76 -62
- package/src/Match.ts +149 -93
- package/src/Pull.ts +8 -8
- package/src/Push.ts +472 -0
- package/src/RefArray.ts +53 -51
- package/src/RefChunk.ts +44 -41
- package/src/RefHashMap.ts +57 -43
- package/src/RefHashSet.ts +21 -31
- package/src/RefSubject.ts +1984 -457
- package/src/Sink.ts +922 -171
- package/src/Stream.ts +32 -20
- package/src/Subject.ts +230 -87
- package/src/TypeId.ts +16 -4
- package/src/Typeclass.ts +31 -32
- package/src/Versioned.ts +220 -168
- package/src/index.ts +78 -6
- package/src/internal/DeferredRef.ts +62 -0
- package/src/internal/UnionToTuple.ts +11 -0
- package/src/internal/core.ts +2491 -1950
- package/src/internal/diff.ts +157 -0
- package/src/internal/effect-loop-operator.ts +466 -0
- package/src/internal/effect-operator.ts +89 -54
- package/src/internal/effect-producer.ts +125 -0
- package/src/internal/helpers.ts +275 -205
- package/src/internal/keyed.ts +192 -241
- package/src/internal/loop-operator.ts +266 -0
- package/src/internal/operator.ts +87 -0
- package/src/internal/protos.ts +29 -104
- package/src/internal/provide.ts +48 -40
- package/src/internal/requestIdleCallback.ts +5 -6
- package/src/internal/share.ts +26 -24
- package/src/internal/sync-operator.ts +68 -27
- package/src/internal/sync-producer.ts +146 -0
- package/src/internal/withKey.ts +64 -74
- package/dist/cjs/Computed.js +0 -115
- package/dist/cjs/Computed.js.map +0 -1
- package/dist/cjs/Filtered.js +0 -95
- package/dist/cjs/Filtered.js.map +0 -1
- package/dist/cjs/Model.js +0 -119
- package/dist/cjs/Model.js.map +0 -1
- package/dist/cjs/RefAsyncData.js +0 -187
- package/dist/cjs/RefAsyncData.js.map +0 -1
- package/dist/cjs/RefAsyncDataArray.js +0 -38
- package/dist/cjs/RefAsyncDataArray.js.map +0 -1
- package/dist/cjs/RefBoolean.js +0 -45
- package/dist/cjs/RefBoolean.js.map +0 -1
- package/dist/cjs/RefNumber.js +0 -49
- package/dist/cjs/RefNumber.js.map +0 -1
- package/dist/cjs/internal/core-ref-subject.js +0 -254
- package/dist/cjs/internal/core-ref-subject.js.map +0 -1
- package/dist/cjs/internal/core-subject.js +0 -108
- package/dist/cjs/internal/core-subject.js.map +0 -1
- package/dist/cjs/internal/deferred-ref.js.map +0 -1
- package/dist/cjs/internal/effect-primitive.js +0 -47
- package/dist/cjs/internal/effect-primitive.js.map +0 -1
- package/dist/cjs/internal/fx-effect-proto.js +0 -58
- package/dist/cjs/internal/fx-effect-proto.js.map +0 -1
- package/dist/cjs/internal/fx-primitive.js +0 -193
- package/dist/cjs/internal/fx-primitive.js.map +0 -1
- package/dist/cjs/internal/fx.js +0 -240
- package/dist/cjs/internal/fx.js.map +0 -1
- package/dist/cjs/internal/matchers.js +0 -34
- package/dist/cjs/internal/matchers.js.map +0 -1
- package/dist/cjs/internal/run.js +0 -54
- package/dist/cjs/internal/run.js.map +0 -1
- package/dist/cjs/internal/schema-ref-subject.js +0 -132
- package/dist/cjs/internal/schema-ref-subject.js.map +0 -1
- package/dist/cjs/internal/versioned-transform.js +0 -46
- package/dist/cjs/internal/versioned-transform.js.map +0 -1
- package/dist/dts/Computed.d.ts +0 -106
- package/dist/dts/Computed.d.ts.map +0 -1
- package/dist/dts/Filtered.d.ts +0 -97
- package/dist/dts/Filtered.d.ts.map +0 -1
- package/dist/dts/Model.d.ts +0 -200
- package/dist/dts/Model.d.ts.map +0 -1
- package/dist/dts/RefAsyncData.d.ts +0 -236
- package/dist/dts/RefAsyncData.d.ts.map +0 -1
- package/dist/dts/RefAsyncDataArray.d.ts +0 -56
- package/dist/dts/RefAsyncDataArray.d.ts.map +0 -1
- package/dist/dts/RefBoolean.d.ts +0 -47
- package/dist/dts/RefBoolean.d.ts.map +0 -1
- package/dist/dts/RefNumber.d.ts +0 -48
- package/dist/dts/RefNumber.d.ts.map +0 -1
- package/dist/dts/internal/core-ref-subject.d.ts +0 -100
- package/dist/dts/internal/core-ref-subject.d.ts.map +0 -1
- package/dist/dts/internal/core-subject.d.ts +0 -5
- package/dist/dts/internal/core-subject.d.ts.map +0 -1
- package/dist/dts/internal/deferred-ref.d.ts +0 -12
- package/dist/dts/internal/deferred-ref.d.ts.map +0 -1
- package/dist/dts/internal/effect-primitive.d.ts +0 -6
- package/dist/dts/internal/effect-primitive.d.ts.map +0 -1
- package/dist/dts/internal/fx-effect-proto.d.ts +0 -30
- package/dist/dts/internal/fx-effect-proto.d.ts.map +0 -1
- package/dist/dts/internal/fx-primitive.d.ts +0 -109
- package/dist/dts/internal/fx-primitive.d.ts.map +0 -1
- package/dist/dts/internal/fx.d.ts +0 -245
- package/dist/dts/internal/fx.d.ts.map +0 -1
- package/dist/dts/internal/matchers.d.ts +0 -33
- package/dist/dts/internal/matchers.d.ts.map +0 -1
- package/dist/dts/internal/run.d.ts +0 -8
- package/dist/dts/internal/run.d.ts.map +0 -1
- package/dist/dts/internal/schema-ref-subject.d.ts +0 -5
- package/dist/dts/internal/schema-ref-subject.d.ts.map +0 -1
- package/dist/dts/internal/versioned-transform.d.ts +0 -17
- package/dist/dts/internal/versioned-transform.d.ts.map +0 -1
- package/dist/esm/Computed.js +0 -103
- package/dist/esm/Computed.js.map +0 -1
- package/dist/esm/Filtered.js +0 -83
- package/dist/esm/Filtered.js.map +0 -1
- package/dist/esm/Model.js +0 -100
- package/dist/esm/Model.js.map +0 -1
- package/dist/esm/RefAsyncData.js +0 -163
- package/dist/esm/RefAsyncData.js.map +0 -1
- package/dist/esm/RefAsyncDataArray.js +0 -27
- package/dist/esm/RefAsyncDataArray.js.map +0 -1
- package/dist/esm/RefBoolean.js +0 -31
- package/dist/esm/RefBoolean.js.map +0 -1
- package/dist/esm/RefNumber.js +0 -35
- package/dist/esm/RefNumber.js.map +0 -1
- package/dist/esm/internal/core-ref-subject.js +0 -242
- package/dist/esm/internal/core-ref-subject.js.map +0 -1
- package/dist/esm/internal/core-subject.js +0 -90
- package/dist/esm/internal/core-subject.js.map +0 -1
- package/dist/esm/internal/deferred-ref.js +0 -23
- package/dist/esm/internal/deferred-ref.js.map +0 -1
- package/dist/esm/internal/effect-primitive.js +0 -41
- package/dist/esm/internal/effect-primitive.js.map +0 -1
- package/dist/esm/internal/fx-effect-proto.js +0 -43
- package/dist/esm/internal/fx-effect-proto.js.map +0 -1
- package/dist/esm/internal/fx-primitive.js +0 -175
- package/dist/esm/internal/fx-primitive.js.map +0 -1
- package/dist/esm/internal/fx.js +0 -216
- package/dist/esm/internal/fx.js.map +0 -1
- package/dist/esm/internal/matchers.js +0 -38
- package/dist/esm/internal/matchers.js.map +0 -1
- package/dist/esm/internal/run.js +0 -32
- package/dist/esm/internal/run.js.map +0 -1
- package/dist/esm/internal/schema-ref-subject.js +0 -121
- package/dist/esm/internal/schema-ref-subject.js.map +0 -1
- package/dist/esm/internal/versioned-transform.js +0 -37
- package/dist/esm/internal/versioned-transform.js.map +0 -1
- package/src/Computed.ts +0 -289
- package/src/Filtered.ts +0 -274
- package/src/Model.ts +0 -483
- package/src/RefAsyncData.ts +0 -547
- package/src/RefAsyncDataArray.ts +0 -135
- package/src/RefBoolean.ts +0 -71
- package/src/RefNumber.ts +0 -77
- package/src/internal/core-ref-subject.ts +0 -528
- package/src/internal/core-subject.ts +0 -143
- package/src/internal/deferred-ref.ts +0 -26
- package/src/internal/effect-primitive.ts +0 -230
- package/src/internal/fx-effect-proto.ts +0 -56
- package/src/internal/fx-primitive.ts +0 -223
- package/src/internal/fx.ts +0 -619
- package/src/internal/matchers.ts +0 -83
- package/src/internal/run.ts +0 -51
- package/src/internal/schema-ref-subject.ts +0 -163
- package/src/internal/versioned-transform.ts +0 -48
package/dist/esm/RefSubject.js
CHANGED
|
@@ -1,217 +1,940 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A RefSubject is
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @since 1.18.0
|
|
2
|
+
* A RefSubject is a Subject that can be used to read and write a value.
|
|
3
|
+
* @since 1.20.0
|
|
6
4
|
*/
|
|
7
5
|
import * as C from "@typed/context";
|
|
8
|
-
import {
|
|
6
|
+
import { Fiber } from "effect";
|
|
7
|
+
import * as Boolean from "effect/Boolean";
|
|
8
|
+
import * as Cause from "effect/Cause";
|
|
9
9
|
import * as Effect from "effect/Effect";
|
|
10
|
-
import
|
|
11
|
-
import
|
|
10
|
+
import * as Equal from "effect/Equal";
|
|
11
|
+
import * as ExecutionStrategy from "effect/ExecutionStrategy";
|
|
12
|
+
import * as Exit from "effect/Exit";
|
|
13
|
+
import { dual, identity } from "effect/Function";
|
|
14
|
+
import * as Layer from "effect/Layer";
|
|
15
|
+
import { sum } from "effect/Number";
|
|
12
16
|
import * as Option from "effect/Option";
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import * as
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
17
|
+
import * as ReadonlyArray from "effect/ReadonlyArray";
|
|
18
|
+
import * as Scope from "effect/Scope";
|
|
19
|
+
import * as core from "./internal/core.js";
|
|
20
|
+
import * as DeferredRef from "./internal/DeferredRef.js";
|
|
21
|
+
import { getExitEquivalence, matchEffectPrimitive, withScope } from "./internal/helpers.js";
|
|
18
22
|
import { FxEffectBase } from "./internal/protos.js";
|
|
19
|
-
import {
|
|
20
|
-
import
|
|
23
|
+
import { runtimeToLayer } from "./internal/provide.js";
|
|
24
|
+
import * as share from "./internal/share.js";
|
|
25
|
+
import * as Sink from "./Sink.js";
|
|
26
|
+
import * as Subject from "./Subject.js";
|
|
27
|
+
import { ComputedTypeId, FilteredTypeId, RefSubjectTypeId, TypeId } from "./TypeId.js";
|
|
21
28
|
import * as Versioned from "./Versioned.js";
|
|
29
|
+
const UNBOUNDED = { concurrency: "unbounded" };
|
|
22
30
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @since 1.18.0
|
|
25
|
-
* @category constructors
|
|
31
|
+
* @since 1.20.0
|
|
26
32
|
*/
|
|
27
|
-
export function fromEffect(
|
|
28
|
-
return
|
|
33
|
+
export function fromEffect(effect, options) {
|
|
34
|
+
return Effect.map(makeCore(effect, options), (core) => new RefSubjectImpl(core));
|
|
29
35
|
}
|
|
30
36
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @since 1.18.0
|
|
33
|
-
* @category constructors
|
|
37
|
+
* @since 1.20.0
|
|
34
38
|
*/
|
|
35
|
-
export function
|
|
36
|
-
return
|
|
39
|
+
export function fromFx(fx, options) {
|
|
40
|
+
return DeferredRef.make(getExitEquivalence(options?.eq ?? Equal.equals)).pipe(Effect.bindTo("deferredRef"), Effect.bind("core", ({ deferredRef }) => makeCore(deferredRef, options)), Effect.tap(({ core, deferredRef }) => Effect.forkIn(fx.run(Sink.make((cause) => Effect.flatMap(Effect.sync(() => deferredRef.done(Exit.failCause(cause))), () => core.subject.onFailure(cause)), (value) => Effect.flatMap(Effect.sync(() => deferredRef.done(Exit.succeed(value))), () => setCore(core, value)))), core.scope)), Effect.map(({ core }) => new RefSubjectImpl(core)));
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
* @since 1.20.0
|
|
44
|
+
*/
|
|
45
|
+
export function fromRefSubject(ref, options) {
|
|
46
|
+
return DeferredRef.make(getExitEquivalence(options?.eq ?? Equal.equals)).pipe(Effect.bindTo("deferredRef"), Effect.bind("core", ({ deferredRef }) => makeCore(deferredRef, options)), Effect.tap(({ core, deferredRef }) => Effect.forkIn(ref.run(Sink.make((cause) => Effect.sync(() => deferredRef.done(Exit.failCause(cause))), (value) => Effect.sync(() => deferredRef.done(Exit.succeed(value))))), core.scope)), Effect.map(({ core }) => new DerivedImpl(core, persistCore(ref, core))));
|
|
47
|
+
}
|
|
48
|
+
function persistCore(ref, core) {
|
|
49
|
+
// Log any errors that fail to persist, but don't fail the consumer
|
|
50
|
+
return Effect.ignoreLogged(Effect.provide(Effect.flatMap(core.deferredRef, (value) => set(ref, value)), core.context));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @since 1.20.0
|
|
54
|
+
*/
|
|
55
|
+
export const make = function make(fxOrEffect, options) {
|
|
56
|
+
if (RefSubjectTypeId in fxOrEffect)
|
|
57
|
+
return fromRefSubject(fxOrEffect, options);
|
|
58
|
+
else if (TypeId in fxOrEffect)
|
|
59
|
+
return fromFx(fxOrEffect, options);
|
|
60
|
+
else
|
|
61
|
+
return fromEffect(fxOrEffect, options);
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* @since 1.20.0
|
|
42
65
|
*/
|
|
43
|
-
export function
|
|
44
|
-
return
|
|
66
|
+
export function of(a, options) {
|
|
67
|
+
return Effect.acquireRelease(withScopeAndFiberId((scope, id) => unsafeMake({
|
|
68
|
+
id,
|
|
69
|
+
initial: Effect.succeed(a),
|
|
70
|
+
initialValue: a,
|
|
71
|
+
options,
|
|
72
|
+
scope
|
|
73
|
+
}), options?.executionStrategy ?? ExecutionStrategy.sequential), (ref) => ref.interrupt);
|
|
74
|
+
}
|
|
75
|
+
const withScopeAndFiberId = (f, strategy) => Effect.fiberIdWith((id) => withScope((scope) => f(scope, id), strategy));
|
|
76
|
+
const emptyContext = C.empty();
|
|
77
|
+
/**
|
|
78
|
+
* @since 1.20.0
|
|
79
|
+
*/
|
|
80
|
+
export function unsafeMake(params) {
|
|
81
|
+
const { id, initial, options, scope } = params;
|
|
82
|
+
return Effect.suspend(() => {
|
|
83
|
+
const core = unsafeMakeCore(initial, id, emptyContext, scope, options);
|
|
84
|
+
// Sometimes we might be instantiating directly from a known value
|
|
85
|
+
// Here we seed the value and ensure the subject has it as well for re-broadcasting
|
|
86
|
+
if ("initialValue" in params) {
|
|
87
|
+
core.deferredRef.done(Exit.succeed(params.initialValue));
|
|
88
|
+
return Effect.map(core.subject.onSuccess(params.initialValue), () => new RefSubjectImpl(core));
|
|
89
|
+
}
|
|
90
|
+
return Effect.succeed(new RefSubjectImpl(core));
|
|
91
|
+
});
|
|
45
92
|
}
|
|
46
|
-
|
|
47
|
-
|
|
93
|
+
class RefSubjectImpl extends FxEffectBase {
|
|
94
|
+
core;
|
|
95
|
+
[ComputedTypeId] = ComputedTypeId;
|
|
96
|
+
[RefSubjectTypeId] = RefSubjectTypeId;
|
|
97
|
+
version;
|
|
98
|
+
interrupt;
|
|
99
|
+
subscriberCount;
|
|
100
|
+
getSetDelete;
|
|
101
|
+
constructor(core) {
|
|
102
|
+
super();
|
|
103
|
+
this.core = core;
|
|
104
|
+
this.version = Effect.sync(() => core.deferredRef.version);
|
|
105
|
+
this.interrupt = interruptCore(core);
|
|
106
|
+
this.subscriberCount = Effect.provide(core.subject.subscriberCount, core.context);
|
|
107
|
+
this.getSetDelete = getSetDelete(core);
|
|
108
|
+
this.runUpdates = this.runUpdates.bind(this);
|
|
109
|
+
this.onSuccess = this.onSuccess.bind(this);
|
|
110
|
+
this.onFailure = this.onFailure.bind(this);
|
|
111
|
+
}
|
|
112
|
+
run(sink) {
|
|
113
|
+
return Effect.matchCauseEffect(this.toEffect(), {
|
|
114
|
+
onFailure: (cause) => sink.onFailure(cause),
|
|
115
|
+
onSuccess: () => Effect.provide(this.core.subject.run(sink), this.core.context)
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
runUpdates(run, lock = true) {
|
|
119
|
+
return lock ? this.core.semaphore.withPermits(1)(run(this.getSetDelete)) : run(this.getSetDelete);
|
|
120
|
+
}
|
|
121
|
+
onSuccess(value) {
|
|
122
|
+
return setCore(this.core, value);
|
|
123
|
+
}
|
|
124
|
+
onFailure(cause) {
|
|
125
|
+
return onFailureCore(this.core, cause);
|
|
126
|
+
}
|
|
127
|
+
toEffect() {
|
|
128
|
+
return getOrInitializeCore(this.core, true);
|
|
129
|
+
}
|
|
48
130
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
131
|
+
class DerivedImpl extends RefSubjectImpl {
|
|
132
|
+
persist;
|
|
133
|
+
constructor(core, persist) {
|
|
134
|
+
super(core);
|
|
135
|
+
this.persist = persist;
|
|
52
136
|
}
|
|
53
|
-
return makeTagged;
|
|
54
137
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
138
|
+
/**
|
|
139
|
+
* @since 1.20.0
|
|
140
|
+
*/
|
|
141
|
+
export const set = dual(2, function set(ref, a) {
|
|
142
|
+
return ref.runUpdates((ref) => ref.set(a));
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* @since 1.20.0
|
|
146
|
+
*/
|
|
147
|
+
export function reset(ref) {
|
|
148
|
+
return ref.runUpdates((ref) => ref.delete);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @since 1.20.0
|
|
152
|
+
*/
|
|
153
|
+
export {
|
|
154
|
+
/**
|
|
155
|
+
* @since 1.20.0
|
|
156
|
+
*/
|
|
157
|
+
reset as delete };
|
|
158
|
+
function getSetDelete(ref) {
|
|
159
|
+
return {
|
|
160
|
+
get: getOrInitializeCore(ref, false),
|
|
161
|
+
set: (a) => setCore(ref, a),
|
|
162
|
+
delete: deleteCore(ref)
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @since 1.20.0
|
|
167
|
+
*/
|
|
168
|
+
export const updateEffect = dual(2, function updateEffect(ref, f) {
|
|
169
|
+
return ref.runUpdates((ref) => Effect.flatMap(Effect.flatMap(ref.get, f), ref.set));
|
|
170
|
+
});
|
|
171
|
+
/**
|
|
172
|
+
* @since 1.20.0
|
|
173
|
+
*/
|
|
174
|
+
export const update = dual(2, function update(ref, f) {
|
|
175
|
+
return updateEffect(ref, (value) => Effect.succeed(f(value)));
|
|
176
|
+
});
|
|
177
|
+
/**
|
|
178
|
+
* @since 1.20.0
|
|
179
|
+
*/
|
|
180
|
+
export const modifyEffect = dual(2, function modifyEffect(ref, f) {
|
|
181
|
+
return ref.runUpdates((ref) => Effect.flatMap(ref.get, (value) => Effect.flatMap(f(value), ([b, a]) => Effect.flatMap(ref.set(a), () => Effect.succeed(b)))));
|
|
182
|
+
});
|
|
183
|
+
/**
|
|
184
|
+
* @since 1.20.0
|
|
185
|
+
*/
|
|
186
|
+
export const modify = dual(2, function modify(ref, f) {
|
|
187
|
+
return modifyEffect(ref, (value) => Effect.succeed(f(value)));
|
|
188
|
+
});
|
|
189
|
+
const isRefSubjectDataFirst = (args) => isRefSubject(args[0]);
|
|
190
|
+
/**
|
|
191
|
+
* @since 1.20.0
|
|
192
|
+
*/
|
|
193
|
+
export const runUpdates = dual(isRefSubjectDataFirst, function runUpdates(ref, f, options) {
|
|
194
|
+
if (!options) {
|
|
195
|
+
return ref.runUpdates(f);
|
|
196
|
+
}
|
|
197
|
+
else if (options.value === "initial") {
|
|
198
|
+
return ref.runUpdates((ref) => Effect.uninterruptibleMask((restore) => Effect.flatMap(ref.get, (initial) => f(ref).pipe(restore, Effect.tapErrorCause(Effect.unifiedFn((cause) => Cause.isInterruptedOnly(cause)
|
|
199
|
+
? options.onInterrupt(initial)
|
|
200
|
+
: Effect.unit))))));
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
return ref.runUpdates((ref) => Effect.uninterruptibleMask((restore) => f(ref).pipe(restore, Effect.tapErrorCause(Effect.unifiedFn((cause) => Cause.isInterruptedOnly(cause)
|
|
204
|
+
? Effect.flatMap(ref.get, options.onInterrupt)
|
|
205
|
+
: Effect.unit)))));
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
class RefSubjectCore {
|
|
209
|
+
initial;
|
|
210
|
+
subject;
|
|
211
|
+
context;
|
|
212
|
+
scope;
|
|
213
|
+
deferredRef;
|
|
214
|
+
semaphore;
|
|
215
|
+
constructor(initial, subject, context, scope, deferredRef, semaphore) {
|
|
216
|
+
this.initial = initial;
|
|
217
|
+
this.subject = subject;
|
|
218
|
+
this.context = context;
|
|
219
|
+
this.scope = scope;
|
|
220
|
+
this.deferredRef = deferredRef;
|
|
221
|
+
this.semaphore = semaphore;
|
|
222
|
+
}
|
|
223
|
+
_fiber = undefined;
|
|
224
|
+
}
|
|
225
|
+
function makeCore(initial, options) {
|
|
226
|
+
return Effect.context().pipe(Effect.bindTo("ctx"), Effect.let("executionStrategy", () => options?.executionStrategy ?? ExecutionStrategy.parallel), Effect.bind("scope", ({ ctx, executionStrategy }) => Scope.fork(C.get(ctx, Scope.Scope), executionStrategy)), Effect.bind("deferredRef", () => DeferredRef.make(getExitEquivalence(options?.eq ?? Equal.equals))), Effect.let("subject", () => Subject.unsafeMake(Math.max(1, options?.replay ?? 1))), Effect.tap(({ scope, subject }) => Scope.addFinalizer(scope, subject.interrupt)), Effect.map(({ ctx, deferredRef, scope, subject }) => new RefSubjectCore(initial, subject, ctx, scope, deferredRef, Effect.unsafeMakeSemaphore(1))));
|
|
227
|
+
}
|
|
228
|
+
function unsafeMakeCore(initial, id, ctx, scope, options) {
|
|
229
|
+
return new RefSubjectCore(initial, Subject.unsafeMake(Math.max(1, options?.replay ?? 1)), ctx, scope, DeferredRef.unsafeMake(id, getExitEquivalence(options?.eq ?? Equal.equals)), Effect.unsafeMakeSemaphore(1));
|
|
230
|
+
}
|
|
231
|
+
function getOrInitializeCore(core, lockInitialize) {
|
|
232
|
+
return Effect.suspend(() => {
|
|
233
|
+
if (core._fiber === undefined && Option.isNone(core.deferredRef.current)) {
|
|
234
|
+
return initializeCoreAndTap(core, lockInitialize);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
return core.deferredRef;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
function initializeCoreEffect(core, lock) {
|
|
242
|
+
const initialize = Effect.onExit(Effect.provide(core.initial, core.context), (exit) => {
|
|
243
|
+
core._fiber = undefined;
|
|
244
|
+
core.deferredRef.done(exit);
|
|
245
|
+
return Effect.unit;
|
|
246
|
+
});
|
|
247
|
+
return Effect.flatMap(Effect.forkIn(lock && core.semaphore ? core.semaphore.withPermits(1)(initialize) : initialize, core.scope), (fiber) => Effect.sync(() => core._fiber = fiber));
|
|
248
|
+
}
|
|
249
|
+
function initializeCore(core, lock) {
|
|
250
|
+
const onSuccess = (a) => {
|
|
251
|
+
core.deferredRef.done(Exit.succeed(a));
|
|
252
|
+
return Effect.succeed(Fiber.succeed(a));
|
|
253
|
+
};
|
|
254
|
+
const onCause = (cause) => {
|
|
255
|
+
core.deferredRef.done(Exit.failCause(cause));
|
|
256
|
+
return Effect.succeed(Fiber.failCause(cause));
|
|
257
|
+
};
|
|
258
|
+
const onError = (e) => onCause(Cause.fail(e));
|
|
259
|
+
return matchEffectPrimitive(core.initial, {
|
|
260
|
+
Success: onSuccess,
|
|
261
|
+
Failure: onCause,
|
|
262
|
+
Some: onSuccess,
|
|
263
|
+
None: onError,
|
|
264
|
+
Left: onError,
|
|
265
|
+
Right: onSuccess,
|
|
266
|
+
Sync: (f) => onSuccess(f()),
|
|
267
|
+
Otherwise: () => initializeCoreEffect(core, lock)
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
function initializeCoreAndTap(core, lock) {
|
|
271
|
+
return Effect.zipRight(initializeCore(core, lock), tapEventCore(core, core.deferredRef));
|
|
272
|
+
}
|
|
273
|
+
function setCore(core, a) {
|
|
274
|
+
const exit = Exit.succeed(a);
|
|
275
|
+
return Effect.suspend(() => {
|
|
276
|
+
if (core.deferredRef.done(exit)) {
|
|
277
|
+
// If the value changed, send an event
|
|
278
|
+
return Effect.as(sendEvent(core, exit), a);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
// Otherwise, just return the current value
|
|
282
|
+
return Effect.succeed(a);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function onFailureCore(core, cause) {
|
|
287
|
+
const exit = Exit.failCause(cause);
|
|
288
|
+
return Effect.suspend(() => {
|
|
289
|
+
if (core.deferredRef.done(exit)) {
|
|
290
|
+
return sendEvent(core, exit);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
return Effect.unit;
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
function interruptCore(core) {
|
|
298
|
+
return Effect.fiberIdWith((id) => {
|
|
299
|
+
core.deferredRef.reset();
|
|
300
|
+
return Scope.close(core.scope, Exit.interrupt(id));
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
function deleteCore(core) {
|
|
304
|
+
return Effect.suspend(() => {
|
|
305
|
+
const current = core.deferredRef.current;
|
|
306
|
+
core.deferredRef.reset();
|
|
307
|
+
if (Option.isNone(current)) {
|
|
308
|
+
return Effect.succeed(Option.none());
|
|
309
|
+
}
|
|
310
|
+
return core.subject.subscriberCount.pipe(Effect.provide(core.context), Effect.flatMap((count) => count > 0 && !core._fiber ? initializeCore(core, false) : Effect.unit), Effect.zipRight(Effect.asSome(current.value)));
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
function tapEventCore(core, effect) {
|
|
314
|
+
return effect.pipe(Effect.exit, Effect.tap((exit) => sendEvent(core, exit)), Effect.flatten);
|
|
315
|
+
}
|
|
316
|
+
function sendEvent(core, exit) {
|
|
317
|
+
if (Exit.isSuccess(exit)) {
|
|
318
|
+
return Effect.provide(core.subject.onSuccess(exit.value), core.context);
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
return Effect.provide(core.subject.onFailure(exit.cause), core.context);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* @since 1.20.0
|
|
326
|
+
*/
|
|
327
|
+
export const mapEffect = dual(2, function mapEffect(versioned, f) {
|
|
328
|
+
return FilteredTypeId in versioned
|
|
329
|
+
? FilteredImpl.make(versioned, (a) => Effect.asSome(f(a)))
|
|
330
|
+
: ComputedImpl.make(versioned, f);
|
|
331
|
+
});
|
|
332
|
+
/**
|
|
333
|
+
* @since 1.20.0
|
|
334
|
+
*/
|
|
335
|
+
export const map = dual(2, function map(versioned, f) {
|
|
336
|
+
return mapEffect(versioned, (a) => Effect.succeed(f(a)));
|
|
337
|
+
});
|
|
338
|
+
/**
|
|
339
|
+
* @since 1.20.0
|
|
340
|
+
*/
|
|
341
|
+
export const filterMapEffect = dual(2, function filterMapEffect(versioned, f) {
|
|
342
|
+
return FilteredImpl.make(versioned, f);
|
|
343
|
+
});
|
|
344
|
+
/**
|
|
345
|
+
* @since 1.20.0
|
|
346
|
+
*/
|
|
347
|
+
export const filterMap = dual(2, function filterMap(versioned, f) {
|
|
348
|
+
return FilteredImpl.make(versioned, (a) => Effect.succeed(f(a)));
|
|
349
|
+
});
|
|
350
|
+
/**
|
|
351
|
+
* @since 1.20.0
|
|
352
|
+
*/
|
|
353
|
+
export const compact = (versioned) => filterMap(versioned, identity);
|
|
354
|
+
/**
|
|
355
|
+
* @since 1.20.0
|
|
356
|
+
*/
|
|
357
|
+
export const filterEffect = dual(2, function filterEffect(versioned, f) {
|
|
358
|
+
return FilteredImpl.make(versioned, (a) => Effect.map(f(a), (b) => b ? Option.some(a) : Option.none()));
|
|
359
|
+
});
|
|
360
|
+
/**
|
|
361
|
+
* @since 1.20.0
|
|
362
|
+
*/
|
|
363
|
+
export const filter = dual(2, function filter(versioned, f) {
|
|
364
|
+
return FilteredImpl.make(versioned, (a) => Effect.succeed(f(a) ? Option.some(a) : Option.none()));
|
|
365
|
+
});
|
|
366
|
+
class ComputedImpl extends Versioned.VersionedTransform {
|
|
367
|
+
input;
|
|
368
|
+
f;
|
|
369
|
+
[ComputedTypeId] = ComputedTypeId;
|
|
370
|
+
constructor(input, f) {
|
|
371
|
+
super(input, (fx) => share.hold(core.mapEffect(fx, f)), Effect.flatMap(f));
|
|
372
|
+
this.input = input;
|
|
373
|
+
this.f = f;
|
|
374
|
+
}
|
|
375
|
+
static make(input, f) {
|
|
376
|
+
return new ComputedImpl(input, f);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
class FilteredImpl extends Versioned.VersionedTransform {
|
|
380
|
+
input;
|
|
381
|
+
f;
|
|
382
|
+
[FilteredTypeId] = FilteredTypeId;
|
|
383
|
+
constructor(input, f) {
|
|
384
|
+
super(input, (fx) => share.hold(core.filterMapEffect(fx, f)), (effect) => Effect.flatten(Effect.flatMap(effect, f)));
|
|
385
|
+
this.input = input;
|
|
386
|
+
this.f = f;
|
|
387
|
+
}
|
|
388
|
+
static make(input, f) {
|
|
389
|
+
return new FilteredImpl(input, f);
|
|
390
|
+
}
|
|
391
|
+
asComputed() {
|
|
392
|
+
return ComputedImpl.make(this.input, this.f);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* @since 1.20.0
|
|
397
|
+
*/
|
|
398
|
+
export const skipRepeatsWith = dual(2, function skipRepeatsWith(ref, eq) {
|
|
399
|
+
const versioned = Versioned.transform(ref, (fx) => core.skipRepeatsWith(fx, eq), identity);
|
|
400
|
+
if (FilteredTypeId in ref) {
|
|
401
|
+
return FilteredImpl.make(versioned, Effect.succeedSome);
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
return ComputedImpl.make(versioned, Effect.succeed);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
export function skipRepeats(ref) {
|
|
408
|
+
return skipRepeatsWith(ref, Equal.equals);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* @since 1.20.0
|
|
412
|
+
*/
|
|
413
|
+
export function transform(ref, from, to) {
|
|
414
|
+
return new RefSubjectTransform(ref, from, to);
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* @since 1.20.0
|
|
418
|
+
*/
|
|
419
|
+
export function transformOrFail(ref, from, to) {
|
|
420
|
+
return new RefSubjectTransformEffect(ref, from, to);
|
|
421
|
+
}
|
|
422
|
+
class RefSubjectTransform extends FxEffectBase {
|
|
423
|
+
ref;
|
|
424
|
+
from;
|
|
425
|
+
to;
|
|
426
|
+
[ComputedTypeId] = ComputedTypeId;
|
|
58
427
|
[RefSubjectTypeId] = RefSubjectTypeId;
|
|
428
|
+
version;
|
|
429
|
+
interrupt;
|
|
430
|
+
subscriberCount;
|
|
431
|
+
constructor(ref, from, to) {
|
|
432
|
+
super();
|
|
433
|
+
this.ref = ref;
|
|
434
|
+
this.from = from;
|
|
435
|
+
this.to = to;
|
|
436
|
+
this.version = ref.version;
|
|
437
|
+
this.interrupt = ref.interrupt;
|
|
438
|
+
this.subscriberCount = ref.subscriberCount;
|
|
439
|
+
}
|
|
440
|
+
run(sink) {
|
|
441
|
+
return this.ref.run(Sink.map(sink, this.from));
|
|
442
|
+
}
|
|
443
|
+
runUpdates(run) {
|
|
444
|
+
return this.ref.runUpdates((ref) => run({
|
|
445
|
+
get: Effect.map(ref.get, this.from),
|
|
446
|
+
set: (b) => Effect.map(ref.set(this.to(b)), this.from),
|
|
447
|
+
delete: Effect.map(ref.delete, Option.map(this.from))
|
|
448
|
+
}));
|
|
449
|
+
}
|
|
450
|
+
onFailure(cause) {
|
|
451
|
+
return this.ref.onFailure(cause);
|
|
452
|
+
}
|
|
453
|
+
onSuccess(value) {
|
|
454
|
+
return this.ref.onSuccess(this.to(value));
|
|
455
|
+
}
|
|
456
|
+
toEffect() {
|
|
457
|
+
return Effect.map(this.ref, this.from);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
class RefSubjectTransformEffect extends FxEffectBase {
|
|
461
|
+
ref;
|
|
462
|
+
from;
|
|
463
|
+
to;
|
|
59
464
|
[ComputedTypeId] = ComputedTypeId;
|
|
465
|
+
[RefSubjectTypeId] = RefSubjectTypeId;
|
|
60
466
|
version;
|
|
467
|
+
interrupt;
|
|
61
468
|
subscriberCount;
|
|
62
|
-
|
|
63
|
-
|
|
469
|
+
subject;
|
|
470
|
+
constructor(ref, from, to) {
|
|
471
|
+
super();
|
|
472
|
+
this.ref = ref;
|
|
473
|
+
this.from = from;
|
|
474
|
+
this.to = to;
|
|
475
|
+
this.version = ref.version;
|
|
476
|
+
this.interrupt = ref.interrupt;
|
|
477
|
+
this.subscriberCount = ref.subscriberCount;
|
|
478
|
+
this.subject = Subject.unsafeMake();
|
|
479
|
+
}
|
|
480
|
+
run(sink) {
|
|
481
|
+
return core.merge(core.mapEffect(this.ref, this.from), this.subject).run(sink);
|
|
482
|
+
}
|
|
483
|
+
runUpdates(run) {
|
|
484
|
+
return this.ref.runUpdates((ref) => run({
|
|
485
|
+
get: Effect.flatMap(ref.get, this.from),
|
|
486
|
+
set: (b) => Effect.matchCauseEffect(Effect.flatMap(this.to(b), ref.set), {
|
|
487
|
+
onFailure: (cause) => Effect.as(this.subject.onFailure(cause), b),
|
|
488
|
+
onSuccess: () => Effect.as(this.subject.onSuccess(b), b)
|
|
489
|
+
}),
|
|
490
|
+
delete: Effect.flatMap(ref.delete, Option.match({
|
|
491
|
+
onNone: () => Effect.succeedNone,
|
|
492
|
+
onSome: (b) => Effect.asSome(this.from(b))
|
|
493
|
+
}))
|
|
494
|
+
}));
|
|
495
|
+
}
|
|
496
|
+
onFailure(cause) {
|
|
497
|
+
return this.subject.onFailure(cause);
|
|
498
|
+
}
|
|
499
|
+
onSuccess(value) {
|
|
500
|
+
return Effect.matchCauseEffect(this.to(value), {
|
|
501
|
+
onFailure: (cause) => this.subject.onFailure(cause),
|
|
502
|
+
onSuccess: (a) => this.ref.onSuccess(a)
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
toEffect() {
|
|
506
|
+
return Effect.flatMap(this.ref, this.from);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* @since 1.20.0
|
|
511
|
+
*/
|
|
512
|
+
export function tuple(refs) {
|
|
513
|
+
const kind = getRefKind(refs);
|
|
514
|
+
switch (kind) {
|
|
515
|
+
case "r":
|
|
516
|
+
return makeTupleRef(refs);
|
|
517
|
+
case "c":
|
|
518
|
+
return makeTupleComputed(refs);
|
|
519
|
+
case "f":
|
|
520
|
+
return makeTupleFiltered(refs);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
const join = (a, b) => {
|
|
524
|
+
if (a === "r")
|
|
525
|
+
return b;
|
|
526
|
+
if (b === "r")
|
|
527
|
+
return a;
|
|
528
|
+
if (a === "f")
|
|
529
|
+
return a;
|
|
530
|
+
if (b === "f")
|
|
531
|
+
return b;
|
|
532
|
+
return "c";
|
|
533
|
+
};
|
|
534
|
+
function getRefKind(refs) {
|
|
535
|
+
let kind = "r";
|
|
536
|
+
for (const ref of refs) {
|
|
537
|
+
if (FilteredTypeId in ref) {
|
|
538
|
+
kind = "f";
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
else if (!(RefSubjectTypeId in ref)) {
|
|
542
|
+
kind = join(kind, "c");
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return kind;
|
|
546
|
+
}
|
|
547
|
+
function makeTupleRef(refs) {
|
|
548
|
+
return new RefSubjectTuple(refs);
|
|
549
|
+
}
|
|
550
|
+
class RefSubjectTuple extends FxEffectBase {
|
|
551
|
+
refs;
|
|
552
|
+
[ComputedTypeId] = ComputedTypeId;
|
|
553
|
+
[RefSubjectTypeId] = RefSubjectTypeId;
|
|
554
|
+
version;
|
|
555
|
+
interrupt;
|
|
556
|
+
subscriberCount;
|
|
557
|
+
versioned;
|
|
558
|
+
getSetDelete;
|
|
559
|
+
constructor(refs) {
|
|
560
|
+
super();
|
|
561
|
+
this.refs = refs;
|
|
562
|
+
this.versioned = Versioned.tuple(refs);
|
|
563
|
+
this.version = this.versioned.version;
|
|
564
|
+
this.interrupt = Effect.all(refs.map((r) => r.interrupt), UNBOUNDED);
|
|
565
|
+
this.subscriberCount = Effect.map(Effect.all(refs.map((r) => r.subscriberCount), UNBOUNDED), ReadonlyArray.reduce(0, sum));
|
|
566
|
+
this.getSetDelete = {
|
|
567
|
+
get: this.versioned,
|
|
568
|
+
set: (a) => Effect.all(refs.map((r, i) => set(r, a[i])), UNBOUNDED),
|
|
569
|
+
delete: Effect.map(Effect.all(refs.map((r) => reset(r)), UNBOUNDED), Option.all)
|
|
570
|
+
};
|
|
571
|
+
this.runUpdates = this.runUpdates.bind(this);
|
|
572
|
+
this.onFailure = this.onFailure.bind(this);
|
|
573
|
+
this.onSuccess = this.onSuccess.bind(this);
|
|
574
|
+
}
|
|
575
|
+
run(sink) {
|
|
576
|
+
return this.versioned.run(sink);
|
|
577
|
+
}
|
|
578
|
+
toEffect() {
|
|
579
|
+
return this.versioned;
|
|
580
|
+
}
|
|
581
|
+
runUpdates(run) {
|
|
582
|
+
return run(this.getSetDelete);
|
|
583
|
+
}
|
|
584
|
+
onFailure(cause) {
|
|
585
|
+
return Effect.all(this.refs.map((ref) => ref.onFailure(cause)));
|
|
586
|
+
}
|
|
587
|
+
onSuccess(value) {
|
|
588
|
+
return Effect.catchAllCause(this.getSetDelete.set(value), (c) => this.onFailure(c));
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
function makeTupleComputed(refs) {
|
|
592
|
+
return new ComputedImpl(Versioned.tuple(refs), Effect.succeed);
|
|
593
|
+
}
|
|
594
|
+
function makeTupleFiltered(refs) {
|
|
595
|
+
return new FilteredImpl(Versioned.tuple(refs), Effect.succeedSome);
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* @since 1.20.0
|
|
599
|
+
*/
|
|
600
|
+
export function struct(refs) {
|
|
601
|
+
const kind = getRefKind(Object.values(refs));
|
|
602
|
+
switch (kind) {
|
|
603
|
+
case "r":
|
|
604
|
+
return makeStructRef(refs);
|
|
605
|
+
case "c":
|
|
606
|
+
return makeStructComputed(refs);
|
|
607
|
+
case "f":
|
|
608
|
+
return makeStructFiltered(refs);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
function makeStructRef(refs) {
|
|
612
|
+
return new RefSubjectStruct(refs);
|
|
613
|
+
}
|
|
614
|
+
class RefSubjectStruct extends FxEffectBase {
|
|
615
|
+
refs;
|
|
616
|
+
[ComputedTypeId] = ComputedTypeId;
|
|
617
|
+
[RefSubjectTypeId] = RefSubjectTypeId;
|
|
618
|
+
version;
|
|
64
619
|
interrupt;
|
|
65
|
-
|
|
620
|
+
subscriberCount;
|
|
621
|
+
versioned;
|
|
622
|
+
getSetDelete;
|
|
623
|
+
constructor(refs) {
|
|
624
|
+
super();
|
|
625
|
+
this.refs = refs;
|
|
626
|
+
this.versioned = Versioned.struct(refs);
|
|
627
|
+
this.version = this.versioned.version;
|
|
628
|
+
this.interrupt = Effect.all(Object.values(refs).map((r) => r.interrupt), UNBOUNDED);
|
|
629
|
+
this.subscriberCount = Effect.map(Effect.all(Object.values(refs).map((r) => r.subscriberCount), UNBOUNDED), ReadonlyArray.reduce(0, sum));
|
|
630
|
+
this.getSetDelete = {
|
|
631
|
+
get: this.versioned,
|
|
632
|
+
set: (a) => Effect.all(Object.keys(refs).map((k) => set(refs[k], a[k])), UNBOUNDED),
|
|
633
|
+
delete: Effect.map(Effect.all(Object.values(refs).map((r) => reset(r)), UNBOUNDED), Option.all)
|
|
634
|
+
};
|
|
635
|
+
this.runUpdates = this.runUpdates.bind(this);
|
|
636
|
+
this.onFailure = this.onFailure.bind(this);
|
|
637
|
+
this.onSuccess = this.onSuccess.bind(this);
|
|
638
|
+
}
|
|
639
|
+
run(sink) {
|
|
640
|
+
return this.versioned.run(sink);
|
|
641
|
+
}
|
|
642
|
+
toEffect() {
|
|
643
|
+
return this.versioned;
|
|
644
|
+
}
|
|
645
|
+
runUpdates(run) {
|
|
646
|
+
return run(this.getSetDelete);
|
|
647
|
+
}
|
|
648
|
+
onFailure(cause) {
|
|
649
|
+
return Effect.all(Object.values(this.refs).map((ref) => ref.onFailure(cause)));
|
|
650
|
+
}
|
|
651
|
+
onSuccess(value) {
|
|
652
|
+
return Effect.catchAllCause(this.getSetDelete.set(value), (c) => this.onFailure(c));
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
function makeStructComputed(refs) {
|
|
656
|
+
return new ComputedImpl(Versioned.struct(refs), Effect.succeed);
|
|
657
|
+
}
|
|
658
|
+
function makeStructFiltered(refs) {
|
|
659
|
+
return new FilteredImpl(Versioned.struct(refs), Effect.succeedSome);
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* @since 1.20.0
|
|
663
|
+
*/
|
|
664
|
+
export function tagged(replay) {
|
|
665
|
+
return (identifier) => new RefSubjectTagged(C.Tagged(identifier), replay);
|
|
666
|
+
}
|
|
667
|
+
class RefSubjectTagged extends FxEffectBase {
|
|
668
|
+
tag;
|
|
669
|
+
replay;
|
|
670
|
+
[ComputedTypeId] = ComputedTypeId;
|
|
671
|
+
[RefSubjectTypeId] = RefSubjectTypeId;
|
|
672
|
+
version;
|
|
673
|
+
interrupt;
|
|
674
|
+
subscriberCount;
|
|
675
|
+
constructor(tag, replay = 0) {
|
|
66
676
|
super();
|
|
67
677
|
this.tag = tag;
|
|
68
|
-
this.
|
|
678
|
+
this.replay = replay;
|
|
69
679
|
this.version = tag.withEffect((ref) => ref.version);
|
|
680
|
+
this.interrupt = tag.withEffect((ref) => ref.interrupt);
|
|
70
681
|
this.subscriberCount = tag.withEffect((ref) => ref.subscriberCount);
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
682
|
+
this.runUpdates = this.runUpdates.bind(this);
|
|
683
|
+
this.onFailure = this.onFailure.bind(this);
|
|
684
|
+
this.onSuccess = this.onSuccess.bind(this);
|
|
74
685
|
}
|
|
75
|
-
|
|
76
|
-
return
|
|
686
|
+
run(sink) {
|
|
687
|
+
return this.tag.withEffect((ref) => ref.run(sink));
|
|
77
688
|
}
|
|
78
689
|
toEffect() {
|
|
79
|
-
return this.
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
onFailure = (cause) => this.tag.withEffect((ref) => ref.onFailure(cause));
|
|
95
|
-
onSuccess = (a) => this.tag.withEffect((ref) => ref.onSuccess(a));
|
|
96
|
-
make = (fx, eq) => this.tag.scoped(make(fx, eq || this.defaultEq));
|
|
97
|
-
of = (value, eq) => this.tag.scoped(of(value, eq));
|
|
98
|
-
provide = (fx, eq) => Effect.provide(this.make(fx, eq || this.defaultEq));
|
|
99
|
-
provideFx = (fx, eq) => provide(this.make(fx, eq || this.defaultEq));
|
|
100
|
-
}
|
|
101
|
-
export function makeWithExtension(fx, f, eq) {
|
|
102
|
-
return coreRefSubject.makeWithExtension(fx, f, eq);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Construct a RefSubject with an initial value and the specified subject.
|
|
106
|
-
* @since 1.18.0
|
|
107
|
-
* @category constructors
|
|
690
|
+
return this.tag.withEffect((ref) => ref);
|
|
691
|
+
}
|
|
692
|
+
runUpdates(run) {
|
|
693
|
+
return this.tag.withEffect((ref) => ref.runUpdates(run));
|
|
694
|
+
}
|
|
695
|
+
onFailure(cause) {
|
|
696
|
+
return this.tag.withEffect((ref) => ref.onFailure(cause));
|
|
697
|
+
}
|
|
698
|
+
onSuccess(value) {
|
|
699
|
+
return this.tag.withEffect((ref) => ref.onSuccess(value));
|
|
700
|
+
}
|
|
701
|
+
make = (fxOrEffect) => this.tag.scoped(make(fxOrEffect));
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* @since 1.20.0
|
|
108
705
|
*/
|
|
109
|
-
export
|
|
706
|
+
export function fromTag(tag, f) {
|
|
707
|
+
return new RefSubjectFromTag(tag, f);
|
|
708
|
+
}
|
|
709
|
+
class RefSubjectFromTag extends FxEffectBase {
|
|
710
|
+
tag;
|
|
711
|
+
f;
|
|
712
|
+
[ComputedTypeId] = ComputedTypeId;
|
|
713
|
+
[RefSubjectTypeId] = RefSubjectTypeId;
|
|
714
|
+
version;
|
|
715
|
+
interrupt;
|
|
716
|
+
subscriberCount;
|
|
717
|
+
_get;
|
|
718
|
+
_fx;
|
|
719
|
+
constructor(tag, f) {
|
|
720
|
+
super();
|
|
721
|
+
this.tag = tag;
|
|
722
|
+
this.f = f;
|
|
723
|
+
this._get = Effect.map(tag, f);
|
|
724
|
+
this._fx = core.fromFxEffect(this._get);
|
|
725
|
+
this.version = Effect.flatMap(this._get, (ref) => ref.version);
|
|
726
|
+
this.interrupt = Effect.flatMap(this._get, (ref) => ref.interrupt);
|
|
727
|
+
this.subscriberCount = Effect.flatMap(this._get, (ref) => ref.subscriberCount);
|
|
728
|
+
}
|
|
729
|
+
run(sink) {
|
|
730
|
+
return this._fx.run(sink);
|
|
731
|
+
}
|
|
732
|
+
toEffect() {
|
|
733
|
+
return Effect.flatten(this._get);
|
|
734
|
+
}
|
|
735
|
+
runUpdates(run) {
|
|
736
|
+
return Effect.flatMap(this._get, (ref) => ref.runUpdates(run));
|
|
737
|
+
}
|
|
738
|
+
onFailure(cause) {
|
|
739
|
+
return Effect.flatMap(this._get, (ref) => ref.onFailure(cause));
|
|
740
|
+
}
|
|
741
|
+
onSuccess(value) {
|
|
742
|
+
return Effect.flatMap(this._get, (ref) => ref.onSuccess(value));
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
export function isRefSubject(u) {
|
|
746
|
+
return isObjectLike(u) && RefSubjectTypeId in u;
|
|
747
|
+
}
|
|
748
|
+
export function isComputed(u) {
|
|
749
|
+
return isObjectLike(u) && ComputedTypeId in u;
|
|
750
|
+
}
|
|
751
|
+
export function isFiltered(u) {
|
|
752
|
+
return isObjectLike(u) && FilteredTypeId in u;
|
|
753
|
+
}
|
|
754
|
+
export function isDerived(u) {
|
|
755
|
+
return isRefSubject(u) && "persist" in u;
|
|
756
|
+
}
|
|
757
|
+
function isObjectLike(u) {
|
|
758
|
+
if (u == null)
|
|
759
|
+
return false;
|
|
760
|
+
const type = typeof u;
|
|
761
|
+
return (type === "object" && !Array.isArray(u)) || type === "function";
|
|
762
|
+
}
|
|
110
763
|
/**
|
|
111
|
-
*
|
|
112
|
-
* @since 1.18.0
|
|
113
|
-
* @category combinators
|
|
764
|
+
* @since 1.20.0
|
|
114
765
|
*/
|
|
115
|
-
export
|
|
766
|
+
export function computedFromTag(tag, f) {
|
|
767
|
+
return new ComputedFromTag(tag, f);
|
|
768
|
+
}
|
|
769
|
+
class ComputedFromTag extends FxEffectBase {
|
|
770
|
+
tag;
|
|
771
|
+
f;
|
|
772
|
+
[ComputedTypeId] = ComputedTypeId;
|
|
773
|
+
version;
|
|
774
|
+
_get;
|
|
775
|
+
constructor(tag, f) {
|
|
776
|
+
super();
|
|
777
|
+
this.tag = tag;
|
|
778
|
+
this.f = f;
|
|
779
|
+
this._get = Effect.map(tag, f);
|
|
780
|
+
this.version = Effect.flatMap(this._get, (ref) => ref.version);
|
|
781
|
+
}
|
|
782
|
+
run(sink) {
|
|
783
|
+
return Effect.flatMap(this._get, (ref) => ref.run(sink));
|
|
784
|
+
}
|
|
785
|
+
toEffect() {
|
|
786
|
+
return Effect.flatten(this._get);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
116
789
|
/**
|
|
117
|
-
*
|
|
118
|
-
* success values separately.
|
|
119
|
-
* @since 1.18.0
|
|
120
|
-
* @category combinators
|
|
790
|
+
* @since 1.20.0
|
|
121
791
|
*/
|
|
122
|
-
export
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
792
|
+
export function filteredFromTag(tag, f) {
|
|
793
|
+
return new FilteredFromTag(tag, f);
|
|
794
|
+
}
|
|
795
|
+
class FilteredFromTag extends FxEffectBase {
|
|
796
|
+
tag;
|
|
797
|
+
f;
|
|
798
|
+
[FilteredTypeId] = FilteredTypeId;
|
|
799
|
+
version;
|
|
800
|
+
_get;
|
|
801
|
+
constructor(tag, f) {
|
|
802
|
+
super();
|
|
803
|
+
this.tag = tag;
|
|
804
|
+
this.f = f;
|
|
805
|
+
this._get = Effect.map(tag, f);
|
|
806
|
+
this.version = Effect.flatMap(this._get, (ref) => ref.version);
|
|
807
|
+
}
|
|
808
|
+
run(sink) {
|
|
809
|
+
return Effect.flatMap(this._get, (ref) => ref.run(sink));
|
|
810
|
+
}
|
|
811
|
+
toEffect() {
|
|
812
|
+
return Effect.flatten(this._get);
|
|
813
|
+
}
|
|
814
|
+
asComputed() {
|
|
815
|
+
return new ComputedFromTag(this.tag, (s) => this.f(s).asComputed());
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* @since 1.20.0
|
|
139
820
|
*/
|
|
140
|
-
export function
|
|
141
|
-
|
|
821
|
+
export const provide = dual(2, function provide(ref, providing) {
|
|
822
|
+
const layer = Layer.isLayer(providing)
|
|
823
|
+
? providing
|
|
824
|
+
: C.isContext(providing)
|
|
825
|
+
? Layer.succeedContext(providing)
|
|
826
|
+
: runtimeToLayer(providing);
|
|
827
|
+
if (isComputed(ref)) {
|
|
828
|
+
return ComputedImpl.make(Versioned.provide(ref, layer), Effect.succeed);
|
|
829
|
+
}
|
|
830
|
+
else if (isFiltered(ref)) {
|
|
831
|
+
return FilteredImpl.make(Versioned.provide(ref, layer), Effect.succeedSome);
|
|
832
|
+
}
|
|
833
|
+
else {
|
|
834
|
+
return new RefSubjectProvide(ref, layer);
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
class RefSubjectProvide extends FxEffectBase {
|
|
838
|
+
ref;
|
|
839
|
+
layer;
|
|
840
|
+
[ComputedTypeId] = ComputedTypeId;
|
|
841
|
+
[RefSubjectTypeId] = RefSubjectTypeId;
|
|
842
|
+
interrupt;
|
|
843
|
+
subscriberCount;
|
|
844
|
+
constructor(ref, layer) {
|
|
845
|
+
super();
|
|
846
|
+
this.ref = ref;
|
|
847
|
+
this.layer = layer;
|
|
848
|
+
this.interrupt = Effect.provide(ref.interrupt, layer);
|
|
849
|
+
this.subscriberCount = Effect.provide(ref.subscriberCount, layer);
|
|
850
|
+
}
|
|
851
|
+
run(sink) {
|
|
852
|
+
return Effect.provide(this.ref.run(sink), this.layer);
|
|
853
|
+
}
|
|
854
|
+
toEffect() {
|
|
855
|
+
return Effect.provide(this.ref, this.layer);
|
|
856
|
+
}
|
|
142
857
|
}
|
|
143
858
|
/**
|
|
144
|
-
*
|
|
859
|
+
* Set the value to true
|
|
145
860
|
* @since 1.18.0
|
|
146
861
|
*/
|
|
147
|
-
export
|
|
148
|
-
return toRefSubject(schema);
|
|
149
|
-
}
|
|
862
|
+
export const asTrue = (ref) => set(ref, true);
|
|
150
863
|
/**
|
|
864
|
+
* Set the value to false
|
|
151
865
|
* @since 1.18.0
|
|
152
866
|
*/
|
|
153
|
-
export const
|
|
867
|
+
export const asFalse = (ref) => set(ref, false);
|
|
154
868
|
/**
|
|
869
|
+
* Toggle the boolean value between true and false
|
|
155
870
|
* @since 1.18.0
|
|
156
871
|
*/
|
|
157
|
-
export const
|
|
872
|
+
export const toggle = (ref) => update(ref, Boolean.not);
|
|
873
|
+
const add = (x) => x + 1;
|
|
158
874
|
/**
|
|
875
|
+
* Set the value to true
|
|
159
876
|
* @since 1.18.0
|
|
160
877
|
*/
|
|
161
|
-
export
|
|
162
|
-
|
|
163
|
-
}
|
|
878
|
+
export const increment = (ref) => update(ref, add);
|
|
879
|
+
const sub = (x) => x - 1;
|
|
164
880
|
/**
|
|
881
|
+
* Set the value to false
|
|
165
882
|
* @since 1.18.0
|
|
166
883
|
*/
|
|
167
|
-
export const
|
|
168
|
-
|
|
884
|
+
export const decrement = (ref) => update(ref, sub);
|
|
885
|
+
/**
|
|
886
|
+
* @since 1.20.0
|
|
887
|
+
*/
|
|
888
|
+
export const slice = dual(3, function slice(ref, drop, take) {
|
|
889
|
+
return new RefSubjectSlice(ref, drop, take);
|
|
890
|
+
});
|
|
891
|
+
/**
|
|
892
|
+
* @since 1.20.0
|
|
893
|
+
*/
|
|
894
|
+
export const drop = dual(2, function drop(ref, drop) {
|
|
895
|
+
return slice(ref, drop, Infinity);
|
|
169
896
|
});
|
|
170
|
-
|
|
897
|
+
/**
|
|
898
|
+
* @since 1.20.0
|
|
899
|
+
*/
|
|
900
|
+
export const take = dual(2, function take(ref, take) {
|
|
901
|
+
return slice(ref, 0, take);
|
|
902
|
+
});
|
|
903
|
+
class RefSubjectSlice extends FxEffectBase {
|
|
171
904
|
ref;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
[RefSubjectTypeId] = RefSubjectTypeId;
|
|
905
|
+
drop;
|
|
906
|
+
take;
|
|
175
907
|
[ComputedTypeId] = ComputedTypeId;
|
|
908
|
+
[RefSubjectTypeId] = RefSubjectTypeId;
|
|
176
909
|
version;
|
|
177
|
-
subscriberCount;
|
|
178
|
-
get;
|
|
179
|
-
delete;
|
|
180
910
|
interrupt;
|
|
181
|
-
|
|
911
|
+
subscriberCount;
|
|
912
|
+
_fx;
|
|
913
|
+
constructor(ref, drop, take) {
|
|
182
914
|
super();
|
|
183
915
|
this.ref = ref;
|
|
184
|
-
this.
|
|
185
|
-
this.
|
|
916
|
+
this.drop = drop;
|
|
917
|
+
this.take = take;
|
|
186
918
|
this.version = ref.version;
|
|
187
|
-
this.subscriberCount = ref.subscriberCount;
|
|
188
|
-
this.get = Effect.map(ref.get, from);
|
|
189
|
-
this.delete = Effect.map(ref.delete, Option.map(from));
|
|
190
919
|
this.interrupt = ref.interrupt;
|
|
920
|
+
this.subscriberCount = ref.subscriberCount;
|
|
921
|
+
this._fx = share.hold(core.slice(ref, drop, take));
|
|
922
|
+
this._effect = ref;
|
|
191
923
|
}
|
|
192
|
-
|
|
193
|
-
return this.
|
|
924
|
+
run(sink) {
|
|
925
|
+
return this._fx.run(sink);
|
|
194
926
|
}
|
|
195
927
|
toEffect() {
|
|
196
|
-
return this.ref
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
mapEffect = (f) => Computed(this, f);
|
|
208
|
-
map = (f) => this.mapEffect((b) => Effect.sync(() => f(b)));
|
|
209
|
-
filterMapEffect = (f) => Filtered(this, f);
|
|
210
|
-
filterMap = (f) => Filtered(this, (a) => Effect.sync(() => f(a)));
|
|
211
|
-
filter = (f) => this.filterMap((a) => f(a) ? Option.some(a) : Option.none());
|
|
212
|
-
filterEffect = (f) => this.filterMapEffect((a) => Effect.map(f(a), (b) => b ? Option.some(a) : Option.none()));
|
|
213
|
-
onSuccess = (b) => this.ref.onSuccess(this.to(b));
|
|
214
|
-
onFailure = (b) => this.ref.onFailure(b);
|
|
215
|
-
skipRepeats = (eq = equals) => Computed(Versioned.transformFx(this, skipRepeatsWith(eq)), Effect.succeed);
|
|
928
|
+
return this.ref;
|
|
929
|
+
}
|
|
930
|
+
runUpdates(run) {
|
|
931
|
+
return this.ref.runUpdates(run);
|
|
932
|
+
}
|
|
933
|
+
onFailure(cause) {
|
|
934
|
+
return this.ref.onFailure(cause);
|
|
935
|
+
}
|
|
936
|
+
onSuccess(value) {
|
|
937
|
+
return this.ref.onSuccess(value);
|
|
938
|
+
}
|
|
216
939
|
}
|
|
217
940
|
//# sourceMappingURL=RefSubject.js.map
|