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.Value

A stored companion value.

Error

type Error
    = BridgeFailure BridgeError
    | MissingPayload
    | DecodeFailure String

Errors reported while reading companion storage.

Commands

set

set : String -> Value -> Cmd msg

Store a value under a key.

get

get : String -> (Result Error Value -> msg) -> Cmd msg

Read a stored value and deliver it to toMsg.

remove

remove : String -> Cmd msg

Remove a stored key.

clear

clear : Cmd msg

Clear all stored values.

setup

setup : Cmd msg

Register the storage platform handler with the companion bridge.

Subscriptions

onStorage

onStorage : (Result Error Value -> msg) -> Sub msg

Receive storage command responses routed through the platform bridge.