Engine for Web Applications

org.cote.js.wires

Class Index

static org.cote.js.wires.wire

version 2.0.0

Static initializer for new Wire instances.

This class participates in the engine library.

Index

Method Index

Methods

newInstance

Creates and returns a new Wire instance.

Syntax

w = newInstance( )

Returns

w as Wire: Returns a new Wire instance.

org.cote.js.wires.Wire

version 2.0.0

Service for extending PrimitiveWire utility, auto-linking PrimitiveWires together, and reusing PrimitiveWires.

This class participates in the engine library.

Index

Example Index

Property Index

Method Index

Examples

Signal and slot example with wires

This demonstrates the use of wires to connect a set of functions in a loose signal and slot implementation. The demonstration uses a single wire that connects test1 to test2, test1 to testC, testC to testX, and testX to testC. The wire is invoked with an array of arguments that is passed to all wired functions. When the wire is invoked, the test1 function is invoked. test1 is wired to two handlers, test2 and testC, and both those handlers are invoked if test1 returns true, or handler execution is forced. If the wire is set to signal, the testC causes the testX handler to be invoked, because testC is also an action. When testX is invoked, it invokes testC again because that handler was used twice. The propogation stops after testC is invoked a second time because handlers can only signal a single time.

Example Code

function testWire(){
  var _w = org.cote.js.wires.wire,w,w2,co;

  co = new CObj();

  w = _w.newInstance();

  /// Test 1 will invoke test 2
  /// This results in 2 function invocations
  ///
  w.wire(0,"test1",0,"test2");
  
  /// With multiple handlers
  ///	Test 1 signals to both.
  ///
  w.wire(0,"test1",co,"testC");
  
  /// AUTO SIGNAL LINK
  /// Because testC is both an action and a handler,
  ///	The first instance of the handler carries over as a signal
  /// This results in 1 function invocation of testX
  ///
  w.wire(co,"testC",0,"testX");
  /// AUTO SIGNAL LINK
  ///	Same as above, except back on testC
  ///	TestX is not invoked again because it is auto-signalling
  /// TestC is invoked again as a handler, but it will not auto-signal a second time
  ///
  w.wire(0,"testX",co,"testC");

  /// Invoke the wire
        ///

  w.invoke([{id:1,data:"the data"}],0,"test1");

}

function test1(o){
  alert('test1');
  return 1;
}
function testX(o){
  alert('testX');
}

function test2(o){
  alert('test 2');
}
function test1_1(o){
  alert('test 1_1');
  return 1;
}

function CObj(){
  this.id = "XX";
  this.object_id = "swc_debug_obj";
  this.testC = function(o){
  	alert("TestC = " + this.id + "\n" + arguments[0].data);
  }
}

Properties

object_config

Object API structure for storing sub structures: object_config.pointers and object_config.status.

Syntax

object = object.object_config

object_id

Unique instance identifier.

Syntax

String = object.object_id

object_type

The type of this object.

Syntax

String = object.object_type

object_version

Version of the object class.

Syntax

String = object.object_version

ready_state

Object load and execution state. Follows: 0 unitialized, 1 through 3 variant, 4 ready, 5 destroyed.

Syntax

int = object.ready_state

Methods

getCanSignal

Returns whether the underlying PrimitiveWire objects signal to each other based on commonality between actions and handlers.

Syntax

b = getCanSignal( )

Returns

b as boolean: Bit indicating whether PrimitiveWires signal to each other.

getObjectId

Returns the unique id of the object.

Syntax

i = getObjectId( )

Returns

i as String: The unique object instance id.

getObjectType

Returns the type of the object.

Syntax

t = getObjectType( )

Returns

t as String: The type of the object instance.

getObjectVersion

Returns the version of the object.

Syntax

v = getObjectVersion( )

Returns

v as String: The version of the object instance.

getPointers

Returns the object_config.pointers sub structure.

Syntax

o = getPointers( )

Returns

o as object: The object_config.pointers substructure.

getReadyState

Returns the state of the object.

Syntax

s = getReadyState( )

Returns

s as int: The object ready state.

getStatus

Returns the object_config.status sub structure.

Syntax

o = getStatus( )

Returns

o as object: The object_config.status substructure.

getWires

Returns an array of wires.

Syntax

w = getWires( )

Returns

w as Array: Array of wire objects.

getWiresHash

Returns a hash of wire identifiers where the key is the id and the value is the index into the wires array.

Syntax

w = getWiresHash( )

Returns

w as Hash: Hash of wire identifiers.

hardWire

Invokes the action of a hardened wire.

Syntax

i = hardWire( o, i, aa, ha, xp, x, yp, y, ep, e, ea )

Parameters

Returns

i as String: Returns the identifier of the newly created hardened wire.

invoke

Invokes a specified function that exists on the wire.

Syntax

v = invoke( a, x, f, b, o )

Parameters

Returns

v as variant: Returns false if unsuccessful, true otherwise.

invokeHardWireAction

Invokes the action of a hardened wire.

Syntax

r = invokeHardWireAction( o, i, a )

Parameters

Returns

r as boolean: Returns true if the chain completed successfully, false if otherwise.

invokeHardWireHandler

Invokes the handler of a hardened wire.

Syntax

r = invokeHardWireHandler( o, i, a )

Parameters

Returns

r as boolean: Returns true if the chain completed successfully, false if otherwise.

invokePrimitive

Invokes a wire, causing the action-handler chain to be processed.

Syntax

r = invokePrimitive( a, i, b, z )

Parameters

Returns

r as boolean: Returns true if the chain completed successfully, false if otherwise.

primitiveWire

Creates and returns a PrimiteWire based on the specified parameters.

Syntax

i = primitiveWire( xp, x, yp, y, ep, e )

Parameters

Returns

i as String: Returns the identifier of the PrimitiveWire object.

setCanSignal

Specifies whether the underlying PrimitiveWire objects signal to each other based on commonality between actions and handlers.

Syntax

void setCanSignal( b )

Parameters

sigterm

Sends termination signal to destroy object.

Syntax

void sigterm( )

wire

Creates and returns a wire based on the specified parameters. This function creates an underlying PrimitiveWire as well as creating linkage to be connected with other wires.

Syntax

i = wire( xp, x, yp, y, ep, e )

Parameters

Returns

i as String: Returns the identifier of the wire object.