package reactiveData

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Reactive map data structure

Signature describing a raw data container ('a data).

Given an implementation of DATA, an incremental version of the container can be produced (via Make).

Parameters

module M : Map.S

Signature

type 'a patch = [ `Add of M.key * 'a | `Del of M.key ] list
include S with type 'a data = 'a M.t and type 'a patch := 'a patch
type 'a t

Reactive version of the data container

type 'a data = 'a M.t

Raw (non-reactive) version of the data container

type 'a msg =
  1. | Patch of 'a patch
    (*

    Patch p triggers the application of p on the current contents

    *)
  2. | Set of 'a data
    (*

    With Set d, d becomes the new content

    *)

Message format

type 'a handle

Handle that permits applying incremental updates

val empty : 'a t

Empty data structure

val create : 'a data -> 'a t * 'a handle

Build a container from initial contents. The handle can be used for performing reactive updates.

val from_event : 'a data -> 'a msg React.E.t -> 'a t

from_event d e is a container whose initial value is d, and which gets updated for every occurrence of e

val from_signal : ?eq:('a -> 'a -> bool) -> 'a data React.S.t -> 'a t

Convert a React signal into a ReactiveData container.

Whenever the signal changes from value v to value v', we detect the differences between v and v', and perform downstream computation (e.g., for map) only on the new and modified elements.

val const : 'a data -> 'a t

Produce a constant container

val patch : 'a handle -> 'a patch -> unit

patch h p applies p on the container corresponding to h

val set : 'a handle -> 'a data -> unit

set h d sets the contents of the container corresponding to h, disregarding previous contents

val map_msg : ('a -> 'b) -> 'a msg -> 'b msg

Transform a message

val map : ('a -> 'b) -> 'a t -> 'b t

map f c applies f on all elements of c, producing a new reactive container c'. Modifying the contents of c leads to modifications of c'. f is applied only on the new or modified elements of c.

val value : 'a t -> 'a data

Return current contents

val fold : ('a -> 'b msg -> 'a) -> 'b t -> 'a -> 'a React.signal

fold f c v accumulates the updates on c with f starting from v.

The result is a signal of value f m_n (f ... (f m_1 v)), where m_1 ... m_n are the messages that have been applied since the beginning of fold. m_1 is a pseudo-message Set l, accounting for the contents l of c at the time when accumulation starts.

val signal : ?eq:('a -> 'a -> bool) -> 'a t -> 'a data React.S.t

Signal corresponding to contents

val event : 'a t -> 'a msg React.E.t

Event whose occurrences correspond to container updates

val filter : (M.key -> 'a -> bool) -> 'a t -> 'a t

filter pred l keeps the elements of l matching pred; gets updated when l is. pred should be a pure function

OCaml

Innovation. Community. Security.