Pebble.Companion.Storage
Persistent companion storage helpers.
Store typed values on the phone companion and read them back across sessions.
import Pebble.Companion.Storage as Storage
type Msg
= GotTheme (Result Storage.Error Storage.Value)
init _ =
( model, Storage.get "theme" GotTheme )
saveTheme : String -> Cmd msg
saveTheme value =
Storage.set "theme" (Storage.StringValue value)
subscriptions _ =
Storage.onStorage GotTheme
For a runnable example, use the companion-demo-storage project template in the IDE.
Values and errors
Value
type Value
= StringValue String
| IntValue Int
| BoolValue Bool
| JsonValue Encode.ValueA stored companion value.
Error
type Error
= BridgeFailure BridgeError
| MissingPayload
| DecodeFailure StringErrors reported while reading companion storage.
Commands
set
set : String -> Value -> Cmd msgStore a value under a key.
get
get : String -> (Result Error Value -> msg) -> Cmd msgRead a stored value and deliver it to toMsg.
remove
remove : String -> Cmd msgRemove a stored key.
clear
clear : Cmd msgClear all stored values.
setup
setup : Cmd msgRegister the storage platform handler with the companion bridge.
Subscriptions
onStorage
onStorage : (Result Error Value -> msg) -> Sub msgReceive storage command responses routed through the platform bridge.