package jsoo_storage

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

Support for LocalStorage

type key = string
type value = string
type old_value = string
type url = string
type change_state =
  1. | Clear
  2. | Insert of key * value
  3. | Remove of key * old_value
  4. | Update of key * old_value * value

This type represents a changeset on the storage

val dump_change_state : change_state -> string

Dump a changestate (mainly for debugging)

val is_supported : unit -> bool

is_supported () returns true if the current storage is supported by the browser, false otherwise.

val handler : t

Returns the JavaScript's representation of the storage object

val length : unit -> int

The length read-only property of the Storage interface returns an integer representing the number of data items stored in the Storage object.

val get : key -> value option

When passed a key name, will return that key's value. (Wrapped into an option)

val set : key -> value -> unit

When passed a key name and value, will add that key to the storage, or update that key's value if it already exists.)

val remove : key -> unit

When passed a key name, will remove that key from the storage.

val clear : unit -> unit

When invoked, clears all stored keys.

val key : int -> key option

When passed a number n, returns the name of the nth key in the storage. The order of keys is user-agent defined, so you should not rely on it.

val at : int -> (key * value) option

Returns the couple Key/Value at a specific position

val to_hashtbl : unit -> (key, value) Stdlib.Hashtbl.t

Produce an Hashtbl.t from a Storage

val iter : (key -> value -> unit) -> unit

applies function f on each key/value of a storage

val find : (key -> value -> bool) -> (key * value) option

find p returns the first element of the storage that satisfies the predicate p. The result is wrapped into an option.

val select : (key -> value -> bool) -> (key, value) Stdlib.Hashtbl.t

select p returns all the elements of the storage that satisfy the predicate p. The results is an Hashtbl.t of the results.

val on_change : ?prefix:string -> (change_state -> url -> unit) -> Js_of_ocaml.Dom.event_listener_id

on_change f trigger f at each changement of the storage. (You can use a prefix to trigger the events only if it concerns a set of keys (with the gived prefix))

val on_clear : (url -> unit) -> Js_of_ocaml.Dom.event_listener_id

on_clear f trigger f at each clear of the storage.

val on_insert : ?prefix:string -> (key -> value -> url -> unit) -> Js_of_ocaml.Dom.event_listener_id

on_insert f trigger f at each insertion in the storage. (You can use a prefix to trigger the events only if it concerns a set of keys (with the gived prefix))

val on_remove : ?prefix:string -> (key -> old_value -> url -> unit) -> Js_of_ocaml.Dom.event_listener_id

on_remove f trigger f at each remove in the storage. (You can use a prefix to trigger the events only if it concerns a set of keys (with the gived prefix))

val on_update : ?prefix:string -> (key -> old_value -> value -> url -> unit) -> Js_of_ocaml.Dom.event_listener_id

on_update f trigger f at each key update in the storage. (You can use a prefix to trigger the events only if it concerns a set of keys (with the gived prefix))

OCaml

Innovation. Community. Security.