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:

Name Description
app Manager state data regarding the app in general
config Configuration data from the ioto.json5 and other config files
auth User authentication data

Accessing State

1
2
3
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.

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:

Property Description
api Backend cloud service API
cognito Cognito config
build App build number
profile Execution profile (prod
name App name
title App display title
version App version (x.y.z)

Auth State

The Auth state store holds authentication state including:

Property Description
account Account object
accountName Account name
accountId Account ID
auth Authentication tokens
authenticated Boolean set to true when the user credentials are authenticated
authorized Boolean set to true when the user is fully logged in
email User's login email address
ready Set to true when the user is logged in and the app is ready to start
role User's authenticated role
user User object
username User login name
userId User ID

Alternatives

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