2011 NEWS 2011-03-23 - NEW MODULE: Uize.Util.PropertyAdapter
The new Uize.Util.PropertyAdapter
module implements a mechanism for connecting two state properties together, with optional bi-directional value adapter code.
1. An Example
The Uize.Util.PropertyAdapter
class makes it easy to connect two state properties in a synchronization relationship, where a change in the value of one of the properties results in the value of the other property being synchronized to the new value of the property that changed.
Consider the following basic example...
EXAMPLE
new Uize.Util.PropertyAdapter ({ propertyA:{ instance:sliderA, property:'minValue' }, propertyB:{ instance:sliderB, property:'minValue' } });
In the above example, the minValue
state properties of two sliders (instances of the Uize.Widget.Bar.Slider
class) are being connected through a property adapter, so that if the value of the minValue
property is modified in sliderA
, the value of the minValue
property of sliderB
is automatically synchronized to that new value, and vice versa.
2. Any Two State Properties
Any two state properties can be connected to each other using a property adapter instance. It can be two properties of the same instance, or it can be properties of two different instances.
The properties being connected can belong to widget instances (i.e. instances of Uize.Widget
subclasses), but the instances owning the properties do not have to be widgets. The instances owning the two properties being connected do not even have to be of the same class. And the two properties do not even have to be of the same type or have the same value range - the Uize.Util.PropertyAdapter
class provides a way to specify a value adapter that should be used to adapt the value in either direction.
3. Comprehensive Docs and Tests
The new Uize.Util.PropertyAdapter
module has comprehensive reference documentation, and is comprehensively unit-tested by the Uize.Test.Uize.Util.PropertyAdapter
unit test module.