@wardic/core 1.1.0 → 1.1.1
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/dist/unstable/AnimationControls.d.ts +110 -0
- package/dist/unstable/AnimationControls.d.ts.map +1 -0
- package/dist/unstable/AnimationControls.js +107 -0
- package/dist/unstable/AnimationControls.js.map +1 -0
- package/dist/unstable/AppearHandoff.d.ts +53 -0
- package/dist/unstable/AppearHandoff.d.ts.map +1 -0
- package/dist/unstable/AppearHandoff.js +23 -0
- package/dist/unstable/AppearHandoff.js.map +1 -0
- package/dist/unstable/Config.d.ts +285 -0
- package/dist/unstable/Config.d.ts.map +1 -0
- package/dist/unstable/Config.js +3 -0
- package/dist/unstable/Config.js.map +1 -0
- package/dist/unstable/FlushGate.d.ts +222 -0
- package/dist/unstable/FlushGate.d.ts.map +1 -0
- package/dist/unstable/FlushGate.js +567 -0
- package/dist/unstable/FlushGate.js.map +1 -0
- package/dist/unstable/FrameTime.d.ts +21 -0
- package/dist/unstable/FrameTime.d.ts.map +1 -0
- package/dist/unstable/FrameTime.js +45 -0
- package/dist/unstable/FrameTime.js.map +1 -0
- package/dist/unstable/MeasuredPairs.d.ts +51 -0
- package/dist/unstable/MeasuredPairs.d.ts.map +1 -0
- package/dist/unstable/MeasuredPairs.js +20 -0
- package/dist/unstable/MeasuredPairs.js.map +1 -0
- package/dist/unstable/OwnValues.d.ts +29 -0
- package/dist/unstable/OwnValues.d.ts.map +1 -0
- package/dist/unstable/OwnValues.js +22 -0
- package/dist/unstable/OwnValues.js.map +1 -0
- package/dist/unstable/PresenceRecord.d.ts +176 -0
- package/dist/unstable/PresenceRecord.d.ts.map +1 -0
- package/dist/unstable/PresenceRecord.js +26 -0
- package/dist/unstable/PresenceRecord.js.map +1 -0
- package/dist/unstable/Reactivity.d.ts +29 -0
- package/dist/unstable/Reactivity.d.ts.map +1 -0
- package/dist/unstable/Reactivity.js +15 -0
- package/dist/unstable/Reactivity.js.map +1 -0
- package/dist/unstable/Report.d.ts +30 -0
- package/dist/unstable/Report.d.ts.map +1 -0
- package/dist/unstable/Report.js +66 -0
- package/dist/unstable/Report.js.map +1 -0
- package/dist/unstable/RetargetLegs.d.ts +189 -0
- package/dist/unstable/RetargetLegs.d.ts.map +1 -0
- package/dist/unstable/RetargetLegs.js +834 -0
- package/dist/unstable/RetargetLegs.js.map +1 -0
- package/dist/unstable/Spine.d.ts +696 -0
- package/dist/unstable/Spine.d.ts.map +1 -0
- package/dist/unstable/Spine.js +2617 -0
- package/dist/unstable/Spine.js.map +1 -0
- package/dist/unstable/Stops.d.ts +82 -0
- package/dist/unstable/Stops.d.ts.map +1 -0
- package/dist/unstable/Stops.js +149 -0
- package/dist/unstable/Stops.js.map +1 -0
- package/dist/unstable/Subject.d.ts +11 -0
- package/dist/unstable/Subject.d.ts.map +1 -0
- package/dist/unstable/Subject.js +12 -0
- package/dist/unstable/Subject.js.map +1 -0
- package/dist/unstable/Timelines.d.ts +51 -0
- package/dist/unstable/Timelines.d.ts.map +1 -0
- package/dist/unstable/Timelines.js +10 -0
- package/dist/unstable/Timelines.js.map +1 -0
- package/dist/unstable/VariableValues.d.ts +27 -0
- package/dist/unstable/VariableValues.d.ts.map +1 -0
- package/dist/unstable/VariableValues.js +19 -0
- package/dist/unstable/VariableValues.js.map +1 -0
- package/dist/unstable/VariantTarget.d.ts +106 -0
- package/dist/unstable/VariantTarget.d.ts.map +1 -0
- package/dist/unstable/VariantTarget.js +185 -0
- package/dist/unstable/VariantTarget.js.map +1 -0
- package/dist/unstable/VariantTree.d.ts +351 -0
- package/dist/unstable/VariantTree.d.ts.map +1 -0
- package/dist/unstable/VariantTree.js +362 -0
- package/dist/unstable/VariantTree.js.map +1 -0
- package/dist/unstable/WardicConfigValue.d.ts +89 -0
- package/dist/unstable/WardicConfigValue.d.ts.map +1 -0
- package/dist/unstable/WardicConfigValue.js +106 -0
- package/dist/unstable/WardicConfigValue.js.map +1 -0
- package/dist/unstable/WardicServices.d.ts +46 -0
- package/dist/unstable/WardicServices.d.ts.map +1 -0
- package/dist/unstable/WardicServices.js +72 -0
- package/dist/unstable/WardicServices.js.map +1 -0
- package/package.json +1 -1
- package/src/unstable/AnimationControls.ts +199 -0
- package/src/unstable/AppearHandoff.ts +81 -0
- package/src/unstable/Config.ts +326 -0
- package/src/unstable/FlushGate.ts +730 -0
- package/src/unstable/FrameTime.ts +52 -0
- package/src/unstable/MeasuredPairs.ts +56 -0
- package/src/unstable/OwnValues.ts +32 -0
- package/src/unstable/PresenceRecord.ts +201 -0
- package/src/unstable/Reactivity.ts +35 -0
- package/src/unstable/Report.ts +75 -0
- package/src/unstable/RetargetLegs.ts +1062 -0
- package/src/unstable/Spine.ts +3275 -0
- package/src/unstable/Stops.ts +221 -0
- package/src/unstable/Subject.ts +13 -0
- package/src/unstable/Timelines.ts +58 -0
- package/src/unstable/VariableValues.ts +27 -0
- package/src/unstable/VariantTarget.ts +246 -0
- package/src/unstable/VariantTree.ts +643 -0
- package/src/unstable/WardicConfigValue.ts +154 -0
- package/src/unstable/WardicServices.ts +125 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a `WardicConfig` gives the Wardic elements below it (#434, Motion's `MotionConfig`), on
|
|
3
|
+
* every binding: its **Config transition**, its reduced motion and whether its
|
|
4
|
+
* animations are skipped (#468).
|
|
5
|
+
*
|
|
6
|
+
* - **The Config transition is an element's own when it gives none,** as Motion's
|
|
7
|
+
* `{ ...config, ...props }`: whatever reads the element's `transition` reads it, a Variant child's in
|
|
8
|
+
* place of its parent's (Q3).
|
|
9
|
+
* - **Its reduced motion** (ADR-0029) is the element's, over the `WardicProvider`'s (Q2), as Motion
|
|
10
|
+
* reads its `MotionConfig`'s per element.
|
|
11
|
+
* - **`skipAnimations`** (#468) makes every animation of the elements below a **Skipped animation**,
|
|
12
|
+
* Motion's `MotionConfig` `skipAnimations`, whatever their reduced motion.
|
|
13
|
+
* - **`isValidProp`** (#443) keeps the props it says aren't valid from being passed on, Motion's
|
|
14
|
+
* `MotionConfig` `isValidProp`.
|
|
15
|
+
* - **`transformPagePoint`** (#443) maps the points a drag or a pan below it uses, Motion's
|
|
16
|
+
* `MotionConfig` `transformPagePoint`.
|
|
17
|
+
* - **A `WardicConfig` inside another** replaces its transition, or with `inherit: true` lays its own
|
|
18
|
+
* fields over it (Motion's `resolveTransition`); one that gives none passes its parent's on, as one
|
|
19
|
+
* that gives no reduced motion, `skipAnimations`, `isValidProp` or `transformPagePoint` passes its parent's.
|
|
20
|
+
*
|
|
21
|
+
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
22
|
+
*
|
|
23
|
+
* @module
|
|
24
|
+
*/
|
|
25
|
+
// Unstable: ADR-0071, decision 5. #672: solid's `wardic-config-value.ts`, moved for the spine's
|
|
26
|
+
// neighbours to read a config's value in core.
|
|
27
|
+
import type * as ReducedMotion from "../ReducedMotion.ts"
|
|
28
|
+
import { constFalse, constUndefined } from "effect/Function"
|
|
29
|
+
import * as Option from "effect/Option"
|
|
30
|
+
import * as Predicate from "effect/Predicate"
|
|
31
|
+
import type * as Config from "./Config.ts"
|
|
32
|
+
import * as VariantTarget from "./VariantTarget.ts"
|
|
33
|
+
|
|
34
|
+
/** What a `WardicConfig` gives below it (#434): one value per config, read where a binding reads it. */
|
|
35
|
+
export interface WardicConfigValue {
|
|
36
|
+
/** Its **Config transition**: read when an element's transition is, so a change starts nothing by itself. */
|
|
37
|
+
readonly transition: () => Config.WardicTransition | undefined
|
|
38
|
+
/**
|
|
39
|
+
* Its reduced motion (ADR-0029): its own, else an enclosing config's, else `undefined` for the
|
|
40
|
+
* `WardicProvider`'s. Read when each animation starts.
|
|
41
|
+
*/
|
|
42
|
+
readonly reducedMotion: () => ReducedMotion.Config | undefined
|
|
43
|
+
/**
|
|
44
|
+
* Whether its animations are skipped (#468): its own, else an enclosing config's, else `undefined`,
|
|
45
|
+
* as `false`. Read when each animation starts.
|
|
46
|
+
*/
|
|
47
|
+
readonly skipAnimations: () => boolean | undefined
|
|
48
|
+
/**
|
|
49
|
+
* Which of an element's own props it passes on (#443, Motion's `MotionConfig` `isValidProp`): its
|
|
50
|
+
* own, else an enclosing config's, else `undefined`, every one. Read as each element is made.
|
|
51
|
+
*/
|
|
52
|
+
readonly isValidProp: () => ((key: string) => boolean) | undefined
|
|
53
|
+
/**
|
|
54
|
+
* Where a drag's or a pan's points are (#443, Motion's `MotionConfig` `transformPagePoint`): its
|
|
55
|
+
* own, else an enclosing config's, else `undefined`, as they are. Read at each drag or pan start.
|
|
56
|
+
*/
|
|
57
|
+
readonly transformPagePoint: () => Config.WardicTransformPoint | undefined
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A `WardicConfig`'s transition (#434): its own, laid over its parent's with `inherit: true` (as a
|
|
62
|
+
* variant's own is over the element's), else its parent's when it gives none.
|
|
63
|
+
*/
|
|
64
|
+
export const configTransitionOf = (own: Config.WardicVariantTransition | undefined, parent: WardicConfigValue | undefined): Config.WardicTransition | undefined =>
|
|
65
|
+
VariantTarget.transitionOfTarget(own, parentTransitionOf(parent))
|
|
66
|
+
|
|
67
|
+
const parentTransitionOf = (parent: WardicConfigValue | undefined): Config.WardicTransition | undefined => {
|
|
68
|
+
if (Predicate.isUndefined(parent)) return undefined
|
|
69
|
+
return parent.transition()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A `WardicConfig`'s reduced motion (#434): its own, else its parent's, else none (the provider's). */
|
|
73
|
+
export const configReducedMotionOf = (own: ReducedMotion.Config | undefined, parent: WardicConfigValue | undefined): ReducedMotion.Config | undefined => {
|
|
74
|
+
if (Predicate.isNotUndefined(own)) return own
|
|
75
|
+
if (Predicate.isUndefined(parent)) return undefined
|
|
76
|
+
return parent.reducedMotion()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A `WardicConfig`'s `skipAnimations` (#468): its own, else its parent's, else none. */
|
|
80
|
+
export const configSkipAnimationsOf = (own: boolean | undefined, parent: WardicConfigValue | undefined): boolean | undefined => {
|
|
81
|
+
if (Predicate.isNotUndefined(own)) return own
|
|
82
|
+
if (Predicate.isUndefined(parent)) return undefined
|
|
83
|
+
return parent.skipAnimations()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A `WardicConfig`'s `isValidProp` (#443): its own, else its parent's, else none. */
|
|
87
|
+
export const configIsValidPropOf = (own: ((key: string) => boolean) | undefined, parent: WardicConfigValue | undefined): ((key: string) => boolean) | undefined => {
|
|
88
|
+
if (Predicate.isNotUndefined(own)) return own
|
|
89
|
+
if (Predicate.isUndefined(parent)) return undefined
|
|
90
|
+
return parent.isValidProp()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A `WardicConfig`'s `transformPagePoint` (#443): its own, else its parent's, else none. */
|
|
94
|
+
export const configTransformPagePointOf = (own: Config.WardicTransformPoint | undefined, parent: WardicConfigValue | undefined): Config.WardicTransformPoint | undefined => {
|
|
95
|
+
if (Predicate.isNotUndefined(own)) return own
|
|
96
|
+
if (Predicate.isUndefined(parent)) return undefined
|
|
97
|
+
return parent.transformPagePoint()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The nearest config's `transformPagePoint` (#443), read at each drag or pan start: `undefined` for none. */
|
|
101
|
+
export const transformPagePointOf = (config: WardicConfigValue | undefined): (() => Config.WardicTransformPoint | undefined) => {
|
|
102
|
+
if (Predicate.isUndefined(config)) return constUndefined
|
|
103
|
+
return () => config.transformPagePoint()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A `transformPagePoint` as core's gestures take it (#618, A1): an `Option`, the same `Some` while the
|
|
108
|
+
* mapping is the same, so a gesture's down allocates nothing.
|
|
109
|
+
*/
|
|
110
|
+
export const pointMapOptionOf = (read: () => Config.WardicTransformPoint | undefined): (() => Option.Option<Config.WardicTransformPoint>) => {
|
|
111
|
+
let last: Option.Option<Config.WardicTransformPoint> = Option.none()
|
|
112
|
+
return () => {
|
|
113
|
+
const now = read()
|
|
114
|
+
if (Predicate.isUndefined(now)) return Option.none()
|
|
115
|
+
if (Option.isSome(last)) {
|
|
116
|
+
if (last.value === now) return last
|
|
117
|
+
}
|
|
118
|
+
last = Option.some(now)
|
|
119
|
+
return last
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The nearest config's `isValidProp` (#443), as an element is made: `undefined` for none. */
|
|
124
|
+
export const isValidPropOf = (config: WardicConfigValue | undefined): ((key: string) => boolean) | undefined => {
|
|
125
|
+
if (Predicate.isUndefined(config)) return undefined
|
|
126
|
+
return config.isValidProp()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Whether an element's animations are skipped (#468), read when each starts: its nearest config's
|
|
131
|
+
* `skipAnimations`. With no config above, never, and nothing made.
|
|
132
|
+
*/
|
|
133
|
+
export const skipAnimationsOf = (config: WardicConfigValue | undefined): (() => boolean) => {
|
|
134
|
+
if (Predicate.isUndefined(config)) return constFalse
|
|
135
|
+
return () => config.skipAnimations() === true
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The reduced motion an element's nearest config sets (#434), now: `undefined` for none, the provider's. */
|
|
139
|
+
export const settingOf = (config: WardicConfigValue | undefined): ReducedMotion.Config | undefined => {
|
|
140
|
+
if (Predicate.isUndefined(config)) return undefined
|
|
141
|
+
return config.reducedMotion()
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* `c` with its **Config transition** as its own when it gives none (#434, Motion's spread): `c` as it
|
|
146
|
+
* is when it has its own or the config gives none.
|
|
147
|
+
*/
|
|
148
|
+
export const withConfigTransition = <C extends { readonly transition?: Config.WardicTransition | undefined }>(c: C, config: WardicConfigValue | undefined): C => {
|
|
149
|
+
if (Predicate.isNotUndefined(c.transition)) return c
|
|
150
|
+
if (Predicate.isUndefined(config)) return c
|
|
151
|
+
const transition = config.transition()
|
|
152
|
+
if (Predicate.isUndefined(transition)) return c
|
|
153
|
+
return { ...c, transition }
|
|
154
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a binding runs Wardic on: the services an Environment gives ({@link WardicServices}), the Layer
|
|
3
|
+
* an app hands its provider ({@link WardicEnv}), and a {@link Runner}, which runs Effects on a built
|
|
4
|
+
* context, synchronously and forked into the Scope it was made in.
|
|
5
|
+
*
|
|
6
|
+
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
// Unstable: ADR-0071, decision 5. #672: `WardicServices` and `WardicEnv` from solid's `runtime.ts`,
|
|
11
|
+
// the Runner from dom's `internal/runner.ts` (ADR-0071 decision 4; #561 round 1, Q6). A
|
|
12
|
+
// `ManagedRuntime` meets the Runner's shape, so Solid hands its runtime over as it is.
|
|
13
|
+
import * as Bool from "effect/Boolean"
|
|
14
|
+
import * as Context from "effect/Context"
|
|
15
|
+
import * as Effect from "effect/Effect"
|
|
16
|
+
import type * as Exit from "effect/Exit"
|
|
17
|
+
import * as Fiber from "effect/Fiber"
|
|
18
|
+
import type * as Layer from "effect/Layer"
|
|
19
|
+
import type * as AtomRegistry from "effect/reactivity/AtomRegistry"
|
|
20
|
+
import * as Scheduler from "effect/Scheduler"
|
|
21
|
+
import * as Scope from "effect/Scope"
|
|
22
|
+
import type * as Announcer from "../Announcer.ts"
|
|
23
|
+
import type * as Clock from "../Clock.ts"
|
|
24
|
+
import type * as DefaultTransition from "../DefaultTransition.ts"
|
|
25
|
+
import type * as FrameLoop from "../FrameLoop.ts"
|
|
26
|
+
import type * as InterpolatorRegistry from "../InterpolatorRegistry.ts"
|
|
27
|
+
import type * as Probe from "../Probe.ts"
|
|
28
|
+
import type * as ReducedMotion from "../ReducedMotion.ts"
|
|
29
|
+
import type * as RefreshFrameSource from "../RefreshFrameSource.ts"
|
|
30
|
+
import type * as Renderer from "../Renderer.ts"
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The services an Environment gives: what the provider's `env` must provide, and what a binding's
|
|
34
|
+
* Effects run with.
|
|
35
|
+
*/
|
|
36
|
+
export type WardicServices =
|
|
37
|
+
| Clock.Clock
|
|
38
|
+
| RefreshFrameSource.RefreshFrameSource
|
|
39
|
+
| FrameLoop.FrameLoop
|
|
40
|
+
| Renderer.Renderer
|
|
41
|
+
| Probe.Probe
|
|
42
|
+
| InterpolatorRegistry.InterpolatorRegistry
|
|
43
|
+
| ReducedMotion.PositionalKeys
|
|
44
|
+
| DefaultTransition.DefaultTransition
|
|
45
|
+
| Announcer.Announcer
|
|
46
|
+
| AtomRegistry.AtomRegistry
|
|
47
|
+
|
|
48
|
+
/** The Layer an app hands its provider: an Environment, giving every one of {@link WardicServices}. */
|
|
49
|
+
export type WardicEnv = Layer.Layer<WardicServices, never, never>
|
|
50
|
+
|
|
51
|
+
/** Runs Effects synchronously, and forked into the Scope it was made in. */
|
|
52
|
+
export interface Runner<R> {
|
|
53
|
+
readonly runSync: <A, E>(effect: Effect.Effect<A, E, R>) => A
|
|
54
|
+
readonly runFork: <A, E>(effect: Effect.Effect<A, E, R>) => Fiber.Fiber<A, E>
|
|
55
|
+
/**
|
|
56
|
+
* Run `effect` now, synchronously, to its Exit: its failure, a defect, or an effect that suspends is
|
|
57
|
+
* in the Exit, never thrown. What a binding closes an owner's Scope with (`OwnerScope.close`).
|
|
58
|
+
*/
|
|
59
|
+
// #672 (PR5-Q1): a ManagedRuntime has it, so a binding's runtime meets the Runner as it is.
|
|
60
|
+
readonly runSyncExit: <A, E>(effect: Effect.Effect<A, E, R>) => Exit.Exit<A, E>
|
|
61
|
+
/**
|
|
62
|
+
* The Scope it was made in: what a service built with it keeps its own fibers in, so closing the
|
|
63
|
+
* Scope ends them, after the service's own cleanup, and awaits them.
|
|
64
|
+
*/
|
|
65
|
+
// #618 (L1): each service opened a detached Scope of its own, closed by a fork or a throwing runSync.
|
|
66
|
+
readonly scope: Scope.Scope
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// A Layer-built service's runner (#132, ADR-0041; dom's `internal/runner.ts` until #672): how the
|
|
70
|
+
// Flush gate's and the projection system's `make` run their Effects after they're built, synchronously
|
|
71
|
+
// and forked, on the context their Layer was built in, forking into its Scope.
|
|
72
|
+
//
|
|
73
|
+
// The context drops a sync scheduler, and keeps any other (ADR-0041, *Amendment (#208)*). A
|
|
74
|
+
// binding's first read builds the Layer inside a `ManagedRuntime.runSync`, whose fiber carries a sync
|
|
75
|
+
// `MixedScheduler`: kept, it would pin every later fork to that scheduler, which resumes a fork's
|
|
76
|
+
// yields on a microtask, where Effect's default resumes them on a macrotask. Without it, forks use
|
|
77
|
+
// the default, as a `ManagedRuntime`'s do. A host's own async scheduler, provided in the Layers it
|
|
78
|
+
// hands Wardic (Foldkit's microtask `MixedScheduler`), is the host's choice: forks keep it (ADR-0027,
|
|
79
|
+
// decision 6: a fork inherits the scheduler it's forked under). A host that provides a *sync* one is
|
|
80
|
+
// overridden too: a sync scheduler is for draining a `runSync`.
|
|
81
|
+
/**
|
|
82
|
+
* A runner over the current context, without a sync scheduler, holding its forks in a set of its own
|
|
83
|
+
* until the current Scope closes and interrupts them (#746: what a `FiberSet` held, so an app ships no
|
|
84
|
+
* FiberSet); a fork after that is interrupted at once. It forks with that context itself (`Effect.runForkWith`), not through
|
|
85
|
+
* `FiberSet.runtime`, which reads the context again in the current fiber, where the building call's
|
|
86
|
+
* scheduler still is: `Effect.provideContext` merges into a fiber's context, it doesn't replace it.
|
|
87
|
+
*/
|
|
88
|
+
// Not `Effect.fnUntraced`, as effect-4's guide prefers: TypeScript can't carry `R` through it, and the
|
|
89
|
+
// runner's context would be `unknown` (#618, H1).
|
|
90
|
+
export const makeRunner = <R>(): Effect.Effect<Runner<R>, never, R | Scope.Scope> =>
|
|
91
|
+
Effect.gen(function* () {
|
|
92
|
+
const context = withoutSyncScheduler(yield* Effect.context<R | Scope.Scope>())
|
|
93
|
+
const fibers = new Set<Fiber.Fiber<unknown, unknown>>()
|
|
94
|
+
let closed = false
|
|
95
|
+
yield* Effect.addFinalizer(() =>
|
|
96
|
+
Effect.suspend(() => {
|
|
97
|
+
closed = true
|
|
98
|
+
return Fiber.interruptAll(fibers)
|
|
99
|
+
}),
|
|
100
|
+
)
|
|
101
|
+
const fork = Effect.runForkWith(context)
|
|
102
|
+
const runFork = <A, E>(effect: Effect.Effect<A, E, R>): Fiber.Fiber<A, E> => {
|
|
103
|
+
const fiber = fork(effect)
|
|
104
|
+
if (closed) {
|
|
105
|
+
fiber.interruptUnsafe()
|
|
106
|
+
return fiber
|
|
107
|
+
}
|
|
108
|
+
fibers.add(fiber)
|
|
109
|
+
fiber.addObserver(() => {
|
|
110
|
+
if (!closed) fibers.delete(fiber)
|
|
111
|
+
})
|
|
112
|
+
return fiber
|
|
113
|
+
}
|
|
114
|
+
return { runSync: Effect.runSyncWith(context), runSyncExit: Effect.runSyncExitWith(context), runFork, scope: Context.get(context, Scope.Scope) }
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* `context` without its scheduler when that one is sync (`runSync`'s), else as it is: a host's
|
|
119
|
+
* async scheduler stays, and with none stored the context has Effect's default already.
|
|
120
|
+
*/
|
|
121
|
+
const withoutSyncScheduler = <S>(context: Context.Context<S>): Context.Context<S> =>
|
|
122
|
+
Bool.match(Context.get(context, Scheduler.Scheduler).executionMode === "sync", {
|
|
123
|
+
onTrue: () => Context.omit(Scheduler.Scheduler)(context),
|
|
124
|
+
onFalse: () => context,
|
|
125
|
+
})
|