Skip to main content

Loading Resources

The dcupl App Loader enables you to configure all relevant resources (models, data, scripts, etc.) in one location and load them in a structured manner. Each resource can have multiple custom tags, which you can define to load in an application or directly via the SDK at runtime of your application.

Combine Resource Tags

Let's take a look at the following example:

[
{
"url": "${baseUrl}/models/my-model-1.dcupl.json",
"type": "model",
"tags": ["model"]
},
{
"url": "${baseUrl}/data/some-data.json",
"type": "data",
"model": "MyModel",
"tags": ["data", "static-data"]
},
{
"url": "${apiUrl}/data/some-api",
"type": "data",
"model": "MyModel",
"tags": ["data", "real-data"]
},
...
]

It is considered best practice to have a common base model for models/data resources and then add more specific tags to distinguish them. In the example provided, we have defined two data resources: one pointing to a static .json file and the other to an API endpoint.

During development, you may prefer to load your static file since you have full control over the data and can make changes to the file as needed.

To load the static file, you can load the resources as follows:

loader.process({
resourceTags: ['model', 'static-data']
})
// loads every resource tagged with either "model" or "static-data"

Now imagine you need to add another data resource that should only be loaded on demand, for instance, if the user enters a specific area of your application. To accommodate this, you can modify the Resources array by adding 'required-data' and 'optional-data' tags as follows:

[
{
"url": "${baseUrl}/models/my-model-1.dcupl.json",
"type": "model",
"tags": ["model"]
},
{
"url": "${baseUrl}/data/some-data.json",
"type": "data",
"model": "MyModel",
"tags": ["data", "static-data", "required-data"]
},
{
"url": "${baseUrl}/data/some-optional-data.json",
"type": "data",
"model": "MyModel",
"tags": ["data", "static-data", "optional-data"]
},
{
"url": "${apiUrl}/data/some-api",
"type": "data",
"model": "MyModel",
"tags": ["data", "real-data", "required-data"]
},
...
]

To load the initial "required" data, you can now combine tags in an array of tags and do the same at a later point in time for the "optional" ones:

loader.process({
resourceTags: ['model', ['static-data', 'required-data']]
})

// loads every resource tagged with either "model" or ("static-data" AND "required-data")

// optional data
loader.process({
resourceTags: ['model', ['static-data', 'optional-data']]
})

Combined resource tags enable you to load your resources more specifically while keeping the tags as general as possible.