module Useri:sig
..end
React
.
Useri
gathers user input as React
signals and events from
a single rendering surface.
Open the module to use it, this defines only modules in your scope.
Note. Before Useri.App.init
is called all signals hold invalid data.
Caveat. Do not expect to be able to fully exploit the possibilities and flexibility of the platforms underlying the backends. This library is a simple abstraction library and thus remains limited by design.
Release 0.0.0-72-g9c6670f — Daniel Bünzli <daniel.buenzl i@erratique.ch>
module Time:sig
..end
module Surface:sig
..end
module Mouse:sig
..end
module Touch:sig
..end
module Key:sig
..end
module Text:sig
..end
module Drop:sig
..end
module Human:sig
..end
module App:sig
..end
This minimal example can be used on both synchronous and asynchronous backends.
A good way of managing side-effects at the boundaries of your functional reactive system is to use a cooperative concurency library and convert event occurences and signal changes to yielding futures/threads (to avoid the problem of forbidden recursive primitive feedback) and convert futures/threads to a primitive event with a single occurence.
You will need however need to cooperate with Useri
's event
loop and give it a high priority as the ability to interact
should never take over a long running computation.
The following code shows how to do that with Lwt and Fut
The Useri.Time
and Useri.Surface
modules provide support for coordinating
input, animation and rendering. We can distinguish two patterns for
rendering:
Useri.Surface.refresh
event, in this step you can
sample signals needed for rendering (as long as they do not
depend on Useri.Surface.refresh
).Useri.Surface.refresh
occurences simply generate a task that is
run outside React's update step, this means that the signals
needed for rendering can be safely sampled using React.S.value
for rendering data.Useri.Surface.refresh
event. It is important to use this event for the following reasons:
Useri.Surface.raster_size
changes.Useri.Surface.refresh
:
E.never
) you need steady refreshing,
use Useri.Surface.steady_refresh
.Useri.Surface.refresh
occurences are generated
immediately after the following signals are created and updated:
Useri.Time.unit
, for animations with a known time span, returns
a signal increasing from 0.
to 1.
during that time span.Useri.Time.count
, for animations with an unknown time span, returns
a signal monotically increasing from 0.
to the time until a specified
event occurs.E.select
them and register the resulting event with
Useri.Surface.set_refresher
.