Model SV Type Reference

Table of contents


Introduction

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:

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.

Constructor

Syntax

new ModelValueSv(info)
ctl.createPage({
	...,
	stateVarInfo:[
		{type:'modelValue', ...},
	],
})
new ModelObjectSv(info)
ctl.createPage({
	...,
	stateVarInfo:[
		{type:'modelObject', ...},
	],
})

Parameters


Instance methods

Inherited methods


component()

Syntax

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.

Return value

A subclass of Component.


doChange()

Syntax

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()

Syntax

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 ''.

Return value

A string containing the unit abbreviation, or ''.


fmtVal()

Syntax

fmtVal()

Returns a formatted version of the value. For Number SV types, it rounds and formats the number according to the fmt string.

Return value

A string containing a formatted version of the current value.


isCurrentUnit()

Syntax

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.

Return value

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()

Syntax

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.

Return value

A Template object, a string, a number, a DOM node, Component object, or an array containing a mix of these types.


setDflt()

Syntax

setDflt()

Sets the value to the current value of the dflt property.


valSync()

Syntax

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.

Parameters


Instance properties

Inherited properties


dflt

The default value, from info.dflt, else info.value, else undefined. setDflt() assigns it, and it is the initial value of the state variable.

Value

Any.


fieldValue

The 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.

Value

Any.


forcedGenCnt

For modelObject state variables, isDifferent() always returns true (every assignment is a change) and each doChange() increments forcedGenCnt, so every SvMonitor reports a change.

Value

A number.


curSv

The 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.

Value

A numeric SV type instance.