Module Note_brr_legacy.Store
Persistent storage.
Persisent key-value store implemented over webstorage. Safe if no one tampers with the storage outside of the program.
XXX.
- This still relies on the jsoo representation, add safer keys with type indexed codecs.
- Provide something sensitive for storage events
Storage scope
Keys
val key : ?ns:Jstr.t -> unit -> 'a Note_brr_legacy.Store.keykey ~ns () is a new storage key in namespace ns. If ns is unspecified, the key lives in a global namespace.
Warning. Reordering invocations of key in the same namespace will most of the time corrupt existing storage. This means that all key calls should always be performed at initialization time. Store.force_version can be used to easily version your store and aleviate this problem.
Storage
In the functions below scope defaults to `Persist.
val mem :
?scope:Note_brr_legacy.Store.scope ->
'a Note_brr_legacy.Store.key ->
boolmem k is true iff k has a mapping.
val add :
?scope:Note_brr_legacy.Store.scope ->
'a Note_brr_legacy.Store.key ->
'a ->
unitadd k v maps k to v.
val rem :
?scope:Note_brr_legacy.Store.scope ->
'a Note_brr_legacy.Store.key ->
unitrem k unbinds k.
val find :
?scope:Note_brr_legacy.Store.scope ->
'a Note_brr_legacy.Store.key ->
'a optionfind k is k's mapping in m, if any.
val get :
?scope:Note_brr_legacy.Store.scope ->
?absent:'a ->
'a Note_brr_legacy.Store.key ->
'aget k is k's mapping. If absent is provided and m has not binding for k, absent is returned.
val clear : ?scope:Note_brr_legacy.Store.scope -> unit -> unitclear (), clears all mapping.
val ev : unit Note.eventev fires on storage changes. FIXME provide something sensitive, e.g. key watching.
Versioning
val force_version : ?scope:Note_brr_legacy.Store.scope -> string -> unitforce_version v checks that the version of the store is v. If it's not it clears the store and sets the version to v.