Skip to content

App State

The Device Manager includes a state management service that serves as a centralized state store for all the components in the application.

The state service allows arbitrary data to be centrally stored and shared between app components. One or more State stores can be created for different state.

The primary advantages of using a centralized state store is the predictable ordering of state changes and the uncoupling of components that need to share state.

State Stores

The Ioto Device Manager provides the following state stores:

NameDescription
appManager state data regarding the app in general
configConfiguration data from the ioto.json5 and other config files
authUser authentication data

Accessing State

js
import {State} from 'manager'

let darkMode = State.app.dark

Creating a State Store

To create a new state store, create a state class and use the Store.add to add the store to the centralized state service.

State stores are available as properties on the State object.

js
import {Store, State} from 'manager'
class MyState {
    temp = 0
    speed: 42
    increment() {
        temp++
    }
    get speed() { return this.speed }
    set speed(v) { this.speed = v }
    async stop() {
        await database.stop()
    }
}
Store.add('my', new MyState())

console.log(State.my.temp)
State.my.stop()
console.log(State.my.speed)

Config State

The Config store holds general config state including:

PropertyDescription
apiBackend cloud service API
cognitoCognito config
buildApp build number
profileExecution profile (prod
nameApp name
titleApp display title
versionApp version (x.y.z)

Auth State

The Auth state store holds authentication state including:

PropertyDescription
accountAccount object
accountNameAccount name
accountIdAccount ID
authAuthentication tokens
authenticatedBoolean set to true when the user credentials are authenticated
authorizedBoolean set to true when the user is fully logged in
emailUser's login email address
readySet to true when the user is logged in and the app is ready to start
roleUser's authenticated role
userUser object
usernameUser login name
userIdUser ID

Alternatives

If you are building your own custom Device Manager, you can also use other state stores such as Pinia.