ensoft / entrance / EnTrance.Feature.Persist

The persist feature provides the ability for any channel to save some data (in JSON format) on the server, and read it back later. This is a basic service intended for slowly-changing small data, not a database.

If multiple browser instances of the same app are open, then saving from one will trigger a notification (decoded with decodeLoad) to all the others, to keep them somewhat in step. If two different changes are saved in close succession, one of them will win, and one will be lost.

Saving data on the server

save : Json.Decode.Value -> EnTrance.Request.Request

Save the provided JSON data on the server, and get an RPC response when complete.

decodeSave : (EnTrance.Types.RpcData () -> msg) -> Json.Decode.Decoder msg

Decode the reply to a save request. The Success payload is just (). Failures should be very uncommon. Takes a message contstructor.

saveAsync : Json.Decode.Value -> EnTrance.Request.Request

Save the provided JSON data on the server, as an async unacknowledged operation. This may be suitable for some non-critical things (eg preferences) where failures don't need UI.

Loading data from the server

load : Json.Decode.Value -> EnTrance.Request.Request

Construct a persist_load request: load the data for this channel from the server, or return the default value provided if there isn't any yet.

This also subscribes this channel to future updates, so that if another browser instance for this channel changes the data we just asked for, we'll get another notification (decodable with decodeLoad]) with the updated data.

decodeLoad : Json.Decode.Decoder data -> (data -> msg) -> Json.Decode.Decoder msg

Decode the response to a persistLoad request - either right after a load request, or later in the lifetime of the app, if another browser instance later changes the data we've requested.

Takes a decoder for the actual data payload and a message constructor.