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.
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
If a service has an init()
function defined, it will be run when first instantiated