Typed Attributes

Some tag attributes support a type prefix to allow for more complexity (or even clarity). Typed attribute values are preceded by a type name and a space. The data type, in particular, will also create sensors to dynamically bind the value.

Auto

The auto type stores most values as strings but will convert ‘true’, ‘false’ and ‘null’ to their non-string counterparts; this is the default type for the value attribute of data tags.

<data name="isBigScreen" value="true" />
<data name="isSmallScreen" value="false" />
<data name="selectedTV" value="null" />

Note: to store these values explicitly as strings, use ‘string true’, ‘string false’ or ‘string null’.

Boolean

The boolean type results in a stored boolean value of true or false. It expects strings of ‘true’ or ‘false’ as inputs.

<data name="isBigScreen" value="bool true" />
<data name="isSmallScreen" value="bool false" />

Note: This is generally not needed – see the auto type.

Config

A config attribute is resolved upon instantiation and does not respond to subsequent changes; it’s a once and done setup variable.

<cog find="someDiv" url="config currentPage" />

In this example, the ‘url’ would be set to whatever string is contained within the config option named currentPage.

Data

Data types provide the name of a data location. The attribute is bound to the data’s value via sensors that are automatically configured in the background.

For instance, a cog can load various URLs dynamically by using a url attribute typed as data.

<cog find="holder" url="data currentPage" />

In this case, the DOM element with an id of holder would always contain a cog whose URL was obtained from a data tag named currentPage. If the value of currentPage changed, a new cog would be loaded, replacing the prior one, using the string value of currentPage as its URL.

Index

The index type signifies that an array index will be used and requires no further naming specifics. It is currently only used as the default setting for the key attribute in chain tags.

Number

The number type attempts to cast and store a value as a Javascript Number.

<data name="retryCount" value="number 3" />
<data name="roughlyE" value="number 2.718" />

Most attributes would store the number as a ‘string’ without this specification.

Prop

The prop type reads a property from the current cog’s script declaration. This is done only once at instantiation and does not respond to later updates.

<data name="appSettings" value="prop defaultSettings" />

Data tags can use the prop type to initialize complex values such as objects or arrays.

Run

The run type executes a function declared in the current cog’s script declaration. This is done only once at instantiation and does not respond to later updates.

<cog find="holder" url="run getCatPage" />

This cog would resolve its ‘url’ based on the result of calling the function ‘getCatPage’ – which should be a method on the current cog that returns a string.

<data name="lastUser" value="run getLastUser" />

Likewise, data tags can run a function to set their initial value.

String

The string type simply specifies that the following value will be treated as a raw string. For cogs, the default type for the ‘url’ attribute is ‘string’.

<cog find="div_one" url="cats_of_the_world.html" />
<cog find="div_two" url="string cats_of_the_world.html" />

These example statements are thus equivalent. They would both load ‘cats_of_the_world.html’ with the full path being relative to the location of the cog file containing this code.

For data locations, the default type is auto – meaning that ‘true’, ‘false’ and ‘null’ would be converted to non-strings.

<data name="trulyTrue" value="true" /> <!-- true -->
<data name="stringTrue" value="string true" />  <!-- 'true' -->
<data name="trulyNull" value="null" />  <!-- null -->
<data name="stringNull" value="string null" /> <!-- 'null' -->
<data name="stringString" value="string string" /> <!-- 'string' -->
<data name="justCat" value="string cat" /> <!-- 'cat' -->
<data name="aStringCat" value="string string cat" /> <!-- 'string cat' -->