Subcomponents may have different requirements depending on the context in which they are operating. For example, a subcomponent might operate differently when running on a production server versus when testing locally off the file system, and differently still when operating in the context of automated tests.
You can find more detailed information on contexts by following the "See also" links in the right sidebar, but in general, the context is made up of
When subcomponents do have different requirements, these can be declared using a demands block. This is a call to the Framework function
A demands block is a way of saying:
"When X is being used in the context of Y, use this special configuration."
The default values for a component's options may be different in different contexts. Demands blocks can be used to provide different values for these options.
Consider the example of a data source component responsible for fetching data from a server. One of the options for this component would likely be the URL of the server. The defaults for the data source might include the following:
During development, you would not want to query the server each time you run tests – at the very least, you wouldn't want to query the production server! Demands blocks allow you to specify a different base URL for the test context, without having to to write complicated
In your unit test files, register a special test-only mini-component using the
fluid.registerNamespace function. This namespace will then exist when your tests run, but not in the production environment.
Demands also allow you to specify a completely different implementation for a given subcomponent in different contexts:
"When someone asks for X in the context of Y, use function Z"
"When someone asks for X in the context of P, use function Q".
In our discussion of Subcomponents, we looked at the example of the User Interface Options (UI Options). One of UI Options' subcomponents was a Preview component. This preview is different in each of the three different versions of UI Options. These different configurations can be created using demands blocks: