Widget Services
In order to make developing widgets even easier, a common set of services is offered to each widget instance, regardless of its implementation technology.
Some of these services are mere adapters to internal APIs and are mostly relevant for tooling, while others are specifically tailored to the respective widget instance, sparing the widget developer to provide context information by himself.
A widget adapter may offer additional services specific to its implementation technology.
For example the AngularJS adapter allows to inject all available AngularJS services and the widget's $scope
object.
Preliminary readings:
Available Services
For a list of all widget services, consult the widget services API documentation.
To help you get started, the most important widget services are:
-
axContext
for passing essential instance information to libraries such as LaxarJS Patterns, also available as$scope
to AngularJS widgets, -
axConfiguration
for application configuration, -
axEventBus
to communicate using publish/subscribe, -
axFeatures
to access instance feature configuration, -
axFlowService
to generate link URLs, -
axLog
for logging.
Mocking Widget Services from Tests
One of the advantages that providing all widget services as injection is improved testability. The LaxarJS Mocks library replaces all widget services with mock versions that do not affect the browser state and that are reset completely between test cases.
The widget service mocks API is defined by LaxarJS Core, and should simplify writing non-trivial tests.
You can configure service mocks just before a widget controller is instantiated by passing a callback to axMocks.widget.whenServicesAvailable
.
The LaxarJS Mocks API docs contain more detailed information.