HValue

Description

Data value synchonization container object.

HValue is the default class to use for data syrchronization purposes. It's smart enough to tell COMM.Values (Value Manager) that it has been changed.

A single HValue instance can be bound to any number of responders, the main client-side responder class is HControl.

When you change the value in one of the instances bound to the HValue instances, all other instances get notified too and the server is also notified and can be further bound on the server side to any number of responders there too.

An instance constructed with "false" (Boolean) as its id is not reported to the server. Such an instance can be used for client-side responder synchronization.

Priority-wise, only the server can create a value id. If a value id is created on the client, the server won't recognize nor accept it.

If a value is changed on the server, it overrides the changes on the client, so no server-client lock is needed in this model.

Instance variables:

id Value Id, used by the whole value management system to identify individual values.
type '[HValue]'
value The container/"payload" data value itself.
views A list of Components that uses this value. Used for automatic value syncronization between responders.

Inherits from:

Constructor Method

The constructor is invoked, when a new instance of HValue is created.

To create a new instance use HValue.nu( id, value ) or new HValue( id, value ).

constructor( id, value )

Description

Constructs a value with the initial value value and the unique id id.

Only the server can create value id's, so use false when constructing from the client. A value with a false id is not reported to the server.

Parameters

id The source id (ideally set by server, should be unique)
value The initial data


Class Methods

implement( interface )

Inherited from: HClass

Description

Copies the members of interface to a HClass or a class inherited from HClass.

Usage:

Defines an interface:
// Create an interface class that calculates the area
var AreaInterface = HClass.extend({
  constructor: null,
  area: function() {
    return this.getWidth() * this.getHeight();
  }
});

// Create a class that contains the coordinates of a rectangle. var Rectangle = HClass.extend({ constructor: function( x, y, width, height ) { this.x = x; this.y = y; this.width = width; this.height = height; }, getWidth: function() { return this.width; }, getHeight: function() { return this.height; } });

// Makes the Rectangle class implement the AreaInterface Rectangle.implement( AreaInterface );

nu( )

Inherited from: HClass

Class members:

Description

nu is a protected class method.

It does the same thing as the new keyword, but it is a class method.

Parameters:

Any parameters are passed on to the constructor method.

Usage:

Creates a class MyClass, then creates two instances of it: myClassInstance1 and myClassInstance2. The end result is the same.
var MyClass = HClass.extend({
  name: 'Foo',
  constructor: function( param1, param2 ){
    var logMsg = [ 'param1:', param1,
                   'param2:', param2,
                   'name:', this.name ];
    console.log( logMsg.join(' ') );
  }
});
// Construction using the new keyword:
var myClassInstance1 = new MyClass( 'one', 'two' );
// Construction using the nu method:
var myClassInstance2 = MyClass.nu( 'one', 'two' );
However, when extending in place, the benefits of the nu method become obvious.

// Extending in place with the new keyword:
var myExtendedClassInstance1 = new (
  MyClass.extend({
    name: 'Bar'
  })
)( 'one', 'two' );
// The same as above, but using the nu method:
var myExtendedClassInstance2 = MyClass.extend({
  name: 'Bar'
}).nu( 'one', 'two' );

extend( instance, static )

Inherited from: HClass

Description

The class method used to extend a class.

If the member name constructor is defined as null instead of a function block in the instance object block, the class is defined as a singleton (single instance class).

Parameters:

instance The object that defines the class instance members.
static The object that defines the static class members.

Returns:

Returns the extended class object.

Usage:

var Point = HClass.extend({
  constructor: function( x, y ) {
    this.x = x;
    this.y = y;
  }
});
var Rectangle = Point.extend({
  // Instance members:
  constructor: function( x, y, width, height ) {
    this.base( x, y );
    this.width = width;
    this.height = height;
  },
  getWidth: function() {
    return this.width;
  },
  getHeight: function() {
    return this.height;
  }
},

// Class Members { description: "this is a Rectangle", getClass: function() { return this; } });


Instance Methods

die( )

Destructor method. Releases all bindings.


get( )

Description

Return the data, returns the self.value instance variable

Returns:
The value instance variable (the data "payload")

set( value )

Description

Replaces the data of the value.

Extend this method, if you want client-side validation in the value itself.

Parameters

value The new data to replace the old data with.


unbind( responder )

Description

Release a responder bound to the HValue instance itself.

Parameters

responder Any responder that is derived from HControl or any other class instance that implements HValueResponder or has compatible typing.


differs( value )

Compares value with self.value.

Returns

true or false, depending on the equality


refresh( )

Calls the setValue method all responders bound to this HValue.


bind( responder )

Description

Bind a responder to the value, use to attach HValues to responders derived from HControl.

Parameters

responder Any responder that is derived from HControl or any other class instance that implements HValueResponder or has compatible typing.


s( value )

Description

Setter for the server.

Just as HValue#set, but doesn't re-notify the server about the change.


release( responder )

Alias of HValue#unbind, opposite of bind.


toString( )

Inherited from: HClass

Protected instance method, returns the instance represented as a String.


valueOf( )

Inherited from: HClass

Protected instance method, returns the value of an instance.


base( )

Inherited from: HClass

This method can be called from any other method to invoke that method's parent



Other Instance Members

prototype = { }

Inherited from: Object

Description

The prototype member of Object defines the instance members. These are copied to the instance object when the new keyword is called.