InputFeed
Input feeds: a target's input as an Environment gives it, event by event, inside the platform's own
dispatch. A feed is a function: given emit and end, it calls emit with each event until the
function it returned stops it, and a source that runs out, as a test's script does, calls end.
InputSource's pointer, keyboard and focus are feeds, and the recognizers are built on them.
watchhandles a feed's events while a Scope is open, each inside its dispatch, so a handler can still prevent the platform's default.watchWithis its form for a handler that can stop.toStreamgives a feed's events as a Stream, still inside the dispatch.byTargetshares one target's feed among everyone who subscribes to it, so hover, press and drag on one Subject start one source, not three.switchedis a subscription its owner opens and closes, for a feed it needs only some of the time.
import * as InputFeed from "@wardic/core/InputFeed"
const input = yield* InputSource.InputSource
yield* InputFeed.watch(input.keyboard(item), {
on: (event) => {
if (event.key === "escape") event.handle()
},
})Interfaces
Handlers
A watch's handlers.
Extended by
Type Parameters
A
A
Properties
on
readonly on: (value) => void;Each event or value, inside the event's dispatch.
Parameters
value
A
Returns
void
onDefect?
readonly onDefect?: OnDefect;A handler's run of throws, at its first. Without it, the run is reported then, and the watch goes on.
onEnd?
readonly onEnd?: () => void;The feed ran out, as a test's script does.
Returns
void
onStop?
readonly onStop?: () => void;Once, when the watch stops: its Scope closed, or its handler done. For a watch that holds something of its own beside the feed.
Returns
void
Switch
A subscription its owner opens and closes: switched's.
Properties
close
readonly close: () => void;Stops the feed, unless it's stopped.
Returns
void
open
readonly open: () => void;Starts the feed, unless it's running.
Returns
void
Type Aliases
InputFeed
type InputFeed<A> = (emit, end) => () => void;A source of events: called with emit and end, it calls emit with each event from then on, and
returns the function that stops it. A source that runs out calls end once, after its last.
Type Parameters
A
A
Parameters
emit
(event) => void
end
() => void
Returns
() => void
OnDefect
type OnDefect = (cause) => void;Where a watch hands its handler's run of throws, at its first, so a binding can report it its own way: a run lasts from a throw to the next call that returns, and the watch goes on with the next event. With none, the run is reported then, on the context the watch started in, and the watch goes on.
Parameters
cause
Cause.Cause<never>
Returns
void
Variables
empty
const empty: InputFeed<never>;A feed with nothing to say: it never emits and never ends.
Functions
byTarget()
function byTarget<A>(lookup): (target) => InputFeed<A>;A feed per target, shared by its subscribers: lookup(target)'s feed starts with the first subscriber
and stops with the last, and every subscriber hears every event, in the order they subscribed. Hover,
press and drag on one target start one source, not three. A source that ends is dropped, so the next
subscriber starts it again.
Type Parameters
A
A
Parameters
lookup
(target) => InputFeed<A>
Returns
(target) => InputFeed<A>
switched()
function switched<A>(
feed,
handle,
onDefect?
): Switch;A subscription to feed its owner opens and closes, each event handed to handle inside its emit, a
run of throws to onDefect at its first. With none, the run is reported then on Effect's default runtime, as
a subscription has no context of its own, and it goes on. For a feed a watch needs only some of the time: a keyboard
press holds its target's keys only while focus is within it, so a Subject at rest holds none. The feed
running out ends nothing; its owner closes it when it's done.
Type Parameters
A
A
Parameters
feed
InputFeed<A>
handle
(event) => void
onDefect?
Returns
toStream()
function toStream<A>(feed): Stream<A>;feed as a Stream: each event is handed on inside its emit, so a consumer waiting on the Stream
handles it before the platform's dispatch returns, and a busy one takes it next, in order. The Stream
ends when the feed does, and stopping the Stream stops the feed.
Type Parameters
A
A
Parameters
feed
InputFeed<A>
Returns
Stream<A>
watch()
function watch<A>(feed, handlers): Effect<void, never, Scope>;Watches feed while the Scope is open: handlers.on hears each event inside its emit, so it can still
prevent the platform's default. For a binding's own input, where it needs no recognizer: a drag
track's grabs, a Reorder item's keys.
Type Parameters
A
A
Parameters
feed
InputFeed<A>
handlers
Handlers<A>
Returns
Effect<void, never, Scope>
watchWith()
function watchWith<A>(
feed,
make,
handlers
): Effect<void, never, Scope>;Watches feed while the Scope is open, with a handler that can stop: make makes this subscription's
handler, which hears each event inside its emit and returns whether to go on. false stops it, even
from inside the feed's start. A run of throws from it goes to handlers.onDefect at its first, else it's
reported then on the context the watch started in, and the watch goes on. handlers.onEnd is told if the
feed runs out, and closing the Scope stops the feed.
Type Parameters
A
A
Parameters
feed
InputFeed<A>
make
() => (event) => boolean
handlers
Pick<Handlers<never>, "onDefect" | "onEnd" | "onStop">
Returns
Effect<void, never, Scope>