Module Server.States

module States: sig .. end

Synchronized values between Server and Client

type 'a callback = ('a -> unit) -> unit 
val register_value : package:Server.Package.package ->
name:string ->
descr:Markdown.text ->
output:'a Server.Request.output ->
get:(unit -> 'a) ->
?add_hook:unit callback -> unit -> Server.Request.signal

Register a (projectified) value and generates the associated signal and request:

If provided, the ~add_hook option is used to register a hook to notify the server of value updates. The hook will be installed only once the client starts to listen for value updates.

Inside Ivette you can use the States.useSyncValue(id) hook to synchronize with this value.

val register_state : package:Server.Package.package ->
name:string ->
descr:Markdown.text ->
data:'a Server.Data.data ->
get:(unit -> 'a) ->
set:('a -> unit) ->
?add_hook:unit callback -> unit -> Server.Request.signal

Register a (projectified) state and generates the associated signal and requests:

If provided, the ~add_hook option is used to register a hook to notify the server of value updates. The hook will be installed only once the client starts to listen for value updates.

Inside Ivette you can use the States.useSyncState(id) hook to synchronize with this state.

type 'a model 

Columns array model

val model : unit -> 'a model

Creates an empty array model.

val column : name:string ->
descr:Markdown.text ->
data:'b Server.Request.output ->
get:('a -> 'b) -> ?default:'b -> 'a model -> unit

Populate an array model with a new field. If a ~default value is given, the field becomes optional and the field is omitted when equal to the default value (compared with =).

val option : name:string ->
descr:Markdown.text ->
data:'b Server.Request.output ->
get:('a -> 'b option) -> 'a model -> unit

Populate an array model with a new optional field.

type 'a array 

Synchronized array state.

val reload : 'a array -> unit

Mark the array to be fully reloaded.

val update : 'a array -> 'a -> unit

Mark an array entry as updated.

val remove : 'a array -> 'a -> unit

Mark an array entry as removed.

val signal : 'a array -> Server.Request.signal

Get the signal associated with the array.

val register_array : package:Server.Package.package ->
name:string ->
descr:Markdown.text ->
key:('a -> string) ->
?keyName:string ->
?keyType:Server.Package.jtype ->
iter:'a callback ->
?add_update_hook:'a callback ->
?add_remove_hook:'a callback ->
?add_reload_hook:unit callback ->
'a model -> 'a array

Register everything necessary to synchronize an array with the client:

The ~key parameter is used to identify array entries, and used to fill the reserved column "id" of entries.

Columns added to the model after registration are not taken into account.

If provided, the ~add_xxx_hook options are used to register hooks to notify the server of corresponding array updates. Each hook will be installed only once the client starts to listen for array updates.

Inside Ivette you can obtain the entries in sync by using the States.useSyncArray() hook.