UIZE JavaScript Framework

2012 NEWS 2012-08-13 - New met and unmet Instance Methods for Classes

The new met and unmet instance methods provide a semantically elegant way to use state properties to represent conditions and to set conditions as having been met or being unmet.

1. The met Instance Method

Sets the specified condition (or conditions) as having been met.

DIFFERENT USAGES

Set a Single Condition as Having Been Met

myInstance.met (propertyNameSTR);

Set Multiple Conditions as Having Been Met

myInstance.met (propertyNamesARRAY);

1.1. For Improved Semantics

The met method is offered as a convenience to improve the semantics of code that is using state properties to represent conditions, and is a very thin wrapper around the set instance method.

The statement myInstance.met ('myCondition') is equivalent to the statement myInstance.set ('myCondition',true). When using a state property to represent a condition, the met method is a semantically elegant way to set the value of the property to true to indicate that the condition represented by the property has been met.

EXAMPLE

MyClass.prototype.initialize = function () {
  // some code here to do the initialization
  this.met ('initialized');
};

In the above example, an initialize instance method is defined for the class MyClass. In the method's implementation, after all the initialization has been performed, the met method is being called to indicate that the initialized condition has been met, where initialized is the name of a state property provided in MyClass. Now, other code can be registered to be executed only once an instance has been initialized by using the once instance method, as follows...

myInstance.once (
  'initialized',
  function () {
    // do some stuff once the instance has been initialized
  }
);

1.2. Set a Single Condition as Having Been Met

In its most typical usage, a single condition can be set as having been met by specifying the name of the condition for the propertyNameSTR parameter.

SYNTAX

myInstance.met (propertyNameSTR);

EXAMPLE

this.met ('someSelected');

1.3. Set Multiple Conditions as Having Been Met

In cases where you wish to set multiple conditions as having been met, the names of those conditions can be supplied by specifying an array for the propertyNamesARRAY parameter.

SYNTAX

myInstance.met (propertyNamesARRAY);

EXAMPLE

this.met (['initialized', 'ready']);

2. The unmet Instance Method

Sets the specified condition (or conditions) as being unmet.

DIFFERENT USAGES

Set a Single Condition as Being Unmet

myInstance.unmet (propertyNameSTR);

Set Multiple Conditions as Being Unmet

myInstance.unmet (propertyNamesARRAY);

2.1. For Improved Semantics

The unmet method is offered as a convenience to improve the semantics of code that is using state properties to represent conditions, and is a very thin wrapper around the set instance method.

The statement myInstance.unmet ('myCondition') is equivalent to the statement myInstance.set ('myCondition',false). When using a state property to represent a condition, the unmet method is a semantically elegant way to set the value of the property to false to indicate that the condition represented by the property is not met / no longer met.

EXAMPLE

MyClass.prototype.die = function () {
  // some code here to tear down the instance
  this.unmet ('initialized');
};

In the above example, a die instance method is defined for the class MyClass. In the method's implementation, after all the tear down steps have been performed, the unmet method is being called to indicate that the initialized condition is no longer met, where initialized is the name of a state property provided in MyClass. It is assumed that some other method, such as an initialize instance method for the class, is responsible for setting the condition as having been met with a statement like this.met ('initialized').

2.2. Set a Single Condition as Being Unmet

In its most typical usage, a single condition can be set as being unmet by specifying the name of the condition for the propertyNameSTR parameter.

SYNTAX

myInstance.unmet (propertyNameSTR);

EXAMPLE

this.unmet ('someSelected');

2.3. Set Multiple Conditions as Being Unmet

In cases where you wish to set multiple conditions as being unmet, the names of those conditions can be supplied by specifying an array for the propertyNamesARRAY parameter.

SYNTAX

myInstance.unmet (propertyNamesARRAY);

EXAMPLE

this.unmet (['initialized', 'ready']);