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.modelValue (ModelValueSv) inherits from StateVar, and modelObject (ModelObjectSv) inherits from modelValue. The type string 'internal' is an alias for modelObject. 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 ModelValueSv implementation returns null (the state variable has no visible representation). A function supplied in info.component replaces this method. Output and Input SV types (see Output SV Type Reference) implement component() by creating a new Component class consisting of just the state variable's render() method, so those subclasses 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. ModelObjectSv also increments forcedGenCnt first so that SvMonitors report a change.
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. The ModelValueSv base implementation returns !!this.unit && !this.isParent, so it is false for a state variable with no unit subName and for a unit parent. Subclasses (Number and Unit SV types) override it.
A Boolean. For child SVs of unit SV types, true if the current value of the unitSelector matches the state variable's unit subName. In the base implementation, true only if the state variable has a unit subName and is not a parent.
render()
Defined only on Output and Input SV types (OutputSv and subclasses), not on ModelValueSv or ModelObjectSv. 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. It is only called by the default OutputSv.component(); the base implementation asserts false, so it must be overridden in the subclass.
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.computeModel() to force synchronous execution of the Model before returning (it does not synchronize the View). 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)dfltThe default value, from info.dflt, else info.value, else undefined. setDflt() assigns it, and it is the initial value of the state variable.
Any.
fieldValueThe last value assigned with val(), whether or not it was valid. It is initialized to dflt. Input SV types use it to restore the contents of an input field that holds an invalid value.
Any.
forcedGenCntFor modelObject state variables, isDifferent() always returns true (every assignment is a change) and each doChange() increments forcedGenCnt, so every SvMonitor reports a change.
A number.
curSvThe base implementation returns the state variable itself. If 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.