Services

Services allow you to create javascript singleton objects these can be as simple as static data objects or have functions, getters, setters and other functionality.

The advantage is that these services are available globally across your interface.

Use Cases

Scenario 1.
You want to have a central data store that is consistent across all of your routes.

Scenario 2
You have an audio player that you want to continue playing even when you navigate to a different route and the player interface is removed from the DOM

Scenario 3
You want a place to store variables for your interface so you can update them in one place

State and scope

The $sdk is available within a service, so you can interact with other services, and access context via the functions and features provided within the SDK and the $sdk.app service

Accessing a Service

The init() function

If a service has an init() function defined, it will be run when first instantiated

Examples

Create a place to store simple variables, and then print them in your interface.
Create a data store, so that you can load content and access it across routes