SharedSource
Shared sources, for the Streams an Environment hands out: each hot and counted, so however many
subscribe, one underlying source runs, started by the first subscriber and stopped when the last one
leaves. byTarget keeps one per target, one observer on each element, and make one for the whole
Environment. An Environment builds its sources with these, as @wardic/dom does.
import * as SharedSource from "@wardic/core/SharedSource"
const resize = yield* SharedSource.byTarget((target) => Effect.succeed(resizesOf(target)))
// Both share one observer on `card`:
Stream.runForEach(resize(card), onLayout)
Stream.runForEach(resize(card), onScroll)Interfaces
Options
byTarget's and make's options.
Properties
idleTimeToLive?
readonly idleTimeToLive?: Input;How long a source with no subscriber left keeps running before it stops, so a quick re-subscribe reuses it. Default: none, stopped at once.
Variables
byTarget
const byTarget: <A>(lookup, options?) => Effect.Effect<(target) => Stream.Stream<A>, never, Scope.Scope>;A shared source per target: a function from a target to a Stream that's hot and counted for that
target. The first subscriber for a target starts lookup(target)'s source, later ones share it, and it
stops when the last one for that target leaves, after idleTimeToLive if it's given.
Type Parameters
A
A
Parameters
lookup
(target) => Effect.Effect<Stream.Stream<A>, never, Scope.Scope>
options?
Returns
Effect.Effect<(target) => Stream.Stream<A>, never, Scope.Scope>
Example
// `resizesOf(target)`: an Environment's own Stream of a target's sizes
const resize = yield* SharedSource.byTarget((target) => Effect.succeed(resizesOf(target)))make
const make: <A>(acquire, options?) => Effect.Effect<Stream.Stream<A>, never, Scope.Scope>;One shared source for the whole Environment: a Stream that's hot and counted. The first subscriber
starts acquire's source, later ones share it, and it stops when the last one leaves, after
idleTimeToLive if it's given. byTarget's form without a target.
Type Parameters
A
A
Parameters
acquire
Effect.Effect<Stream.Stream<A>, never, Scope.Scope>
options?
Returns
Effect.Effect<Stream.Stream<A>, never, Scope.Scope>
Example
// `viewportChanges`: an Environment's own Stream of its viewport's size
const viewport = yield* SharedSource.make(Effect.succeed(viewportChanges))
Stream.runForEach(viewport, onResize) // one listener, however many subscribe