Model SV types will schedule the execution of the Model followed by synchronization of the View when changed. Instances of Input SV types will have an isInput property set to true. Instances of Output SV types will have an isOutput property set to true.
There are two built-in SV types that are the superclasses for all Model state variable types:
modelValuemodelValue state variables declare a change when an assigned value is different (isDIfferent()) than the current value. The value is typically a primitive JavaScript type.modelObjectmodelObject state variables declare a change whenever a value is assigned, regardless of whether it is different. The value is typically a JavaScript Object.Both types inherit from StateVar. Use modelObject for objects, and be sure to assign the object to the value every time you change it.
'modelValue', class: ModelValueSv'modelObject', class: ModelObjectSvnew ModelValueSv(info)
ctl.createPage({
...,
stateVarInfo:[
{type:'modelValue', ...},
],
})
new ModelObjectSv(info)
ctl.createPage({
...,
stateVarInfo:[
{type:'modelObject', ...},
],
})
infoinfo object can contain the following properties, but subclasses may have additional properties:info properties.dfltdflt is not specified, the initial value is used, or undefined if no initial value is specified.component()
Returns a Component that, when instantiated in the View, will represent the state variable to the user. The default Component will create a new Component class consisting of just the state variable's render() method. In other words, a Model SV type subclass can simply provide a render() method and no component() method if no other Component functionality is required.
A subclass of Component.
doChange()
Do what’s required when a change happens. By default, it calls all the change listeners, then calls ctl.sync() to schedule Model execution and synchronization of the View.
fmtUnit()
Returns the abbreviation for the current unit if this state variable is a Unit SV type, a unit child of a Unit SV type, or a Number SV type that has a unit subName. For example, if the current unit were kilograms, then it would return 'kg.'. If no unit exists, it returns ''.
A string containing the unit abbreviation, or ''.
fmtVal()
Returns a formatted version of the value. For Number SV types, it rounds and formats the number according to the fmt string.
A string containing a formatted version of the current value.
isCurrentUnit()
If this state variable is a unit child of a Unit SV type, it returns true if the value of unitSelector state variable associated with the parent state variable’s unitClass matches this state variable's unit subName. Otherwise, it returns true.
A Boolena. True for non-numeric SV types, or non-Unit SV types. True for child SVs of unit SV types if the current value of the unitSelector matches the state variable's unit subName.
render()
Returns a A Template object, a string, a number, a DOM node, Component object, or an array containing a mix of these types that represent the desired user interface elements for the state variable. This is the same as the Component class' render() method. This method is only called when no subclass component() method is provided.
A Template object, a string, a number, a DOM node, Component object, or an array containing a mix of these types.
setDflt()
Sets the value to the current value of the dflt property.
valSync(value)
Sets the state variable value using the val() method and calls ctl.doSync() to force synchronous execution of the Model and View before returning. Self-test code uses this to simulate user input and ensure that the value change is fully processed so that calculated values can be tested immediately following the call.
value (optional)curSvIf this state variable is a Unit SV type or a unit child of a Unit SV type, it returns the Number state variable for the unit that matches the value of the unitSelector state variable associated with the parent state variable’s unitClass. You cannot change this property.
A numeric SV type instance.