Views
Overview
Writing assets or views is as simple as creating a React element using your base DSL components:
When compiled, this would produce the following JSON.
Not only is the source DSL content a fraction of the output object’s size (making it easier to read and maintain) as the base components use the same TypeScript types as the assets themselves, you will receive in editor suggestions and type checks as you author your content.
View Concepts in DSL
Templates
Templates are included via the @player-tools/dsl
package. This can be used in any asset slot:
Templates can be nested within one another, and the auto-id generation will handle adding the _index_
information to any generated id
.
Switches
The @player-tools/dsl
module also includes support for static and dynamic switches.
Use the isDynamic
flag to denote this should be a dynamicSwitch
instead of a staticSwitch
:
DSL Benefits in Views
IDs
Any asset can accept an id
property, however automatic ID creation is supported out of the box by the base Asset
component and it’s generation behavior can be further customized via your component’s implementation.
Collection/Text Creation
In the event that an asset object is expected, but a string
or number
is found, Player will attempt to automatically create a text node, provided the asset-library has a text-asset-factory configured.
Similarly, if a single asset is expected but a list of them is found instead, Player will attempt to create a collection asset provided the library has the proper configuration set.
Meta Components
As DSL components are React component, they can be composed into reusable building blocks to simplify and abstract away common UI patterns. By centralizing these patterns, code duplication can be minimized and updates across multiple sets of content can be simplified. These composed components don’t just have to be built on top of the base set of DSL components, DSL components themselves can offer common shortcuts for behavior. For example, if we wanted to offer an out of the box Action
component that could be used as a Next
action asset, we could export the following from the DSL components library.