Hemi JavaScript Framework
Hemi.wires
Description
The Wire Service is used to chain multiple primitive wires (which connect disparate functions).
Class Index
static Hemi.wires.service
version 3.1.9
Static initializer for new Wire instances.
Index
Method Index
- public newInstance: Creates and returns a new Wire instance.
Methods
newInstance
Creates and returns a new Wire instance.
Syntax
w = newInstance(
)
Returns
w as Wire: Returns a new Wire instance.
Hemi.wires.serviceImpl
version 3.1.9
Service for extending PrimitiveWire utility, auto-linking PrimitiveWires together, and reusing PrimitiveWires.
Index
Example Index
- 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.
Property Index
- public object_id (internal): Unique instance identifier.
- public object_type (internal): The type of this object.
- public object_version (internal): Version of the object class.
- public ready_state (internal): Object load and execution state. Follows: 0 unitialized, 1 through 3 variant, 4 ready, 5 destroyed.
Method Index
- public getCanSignal: Returns whether the underlying PrimitiveWire objects signal to each other based on commonality between actions and handlers.
- public getObjectId: Returns the unique id of the object.
- public getObjectType: Returns the type of the object.
- public getObjectVersion: Returns the version of the object.
- public getReadyState: Returns the state of the object.
- public getWires: Returns an array of wires.
- public getWiresHash: Returns a hash of wire identifiers where the key is the id and the value is the index into the wires array.
- public hardWire: Invokes the action of a hardened wire.
- public invoke: Invokes a specified function that exists on the wire.
- public invokeHardWireAction: Invokes the action of a hardened wire.
- public invokeHardWireHandler: Invokes the handler of a hardened wire.
- public invokePrimitive: Invokes a wire, causing the action-handler chain to be processed.
- public primitiveWire: Creates and returns a PrimiteWire based on the specified parameters.
- public setCanSignal: Specifies whether the underlying PrimitiveWire objects signal to each other based on commonality between actions and handlers.
- public sigterm: Sends termination signal to destroy object.
- public 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.
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 = Hemi.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_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.
getReadyState
Returns the state of the object.
Syntax
s = getReadyState(
)
Returns
s as int: The object ready state.
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
- o as PrimitiveWire : A PrimitiveWire object.
- i as String : Identifier of a primitive wire.
- aa as array (optional): Arguments to pass to the action function.
- ha as array (optional): Arguments to pass to the handler function.
- xp as variant : Object, or string evaluation, to which the action function is defined.
- x as function : The action function.
- yp as variant : Object, or string evaluation, to which the handler function is defined.
- y as function : The hander function.
- ep as variant : Object, or string evaluation, to which the error function is defined.
- e as function : The error function.
- ea as array (optional): Arguments to pass to the error function.
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
- a as array : Arguments to pass to the wired functions.
- x as variant : String evaluation or object on which the specified wire function exists.
- f as String : Name of function to invoke.
- b as boolean : Force the wire handler to execute.
- o as boolean : Bit specifying only the handler should fire.
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
- o as PrimitiveWire : A PrimitiveWire object.
- i as String : Identifier of a wire.
- a as array (optional): Arguments to pass to the wired functions.
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
- o as PrimitiveWire : A PrimitiveWire object.
- i as String : Identifier of a wire.
- a as array (optional): Arguments to pass to the wired functions.
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
- a as array (optional): Arguments to pass to the wired functions.
- i as String : Identifier of the primitive wire to invoke.
- b as boolean (optional): Bit indicating only the handler should be fired.
- z as boolean (optional): Bit indicating the handler should be skipped.
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
- xp as variant : Object, or string evaluation, to which the action function is defined.
- x as function : The action function.
- yp as variant : Object, or string evaluation, to which the handler function is defined.
- y as function : The hander function.
- ep as variant : Object, or string evaluation, to which the error function is defined.
- e as function : The error function.
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
- b as boolean : Bit indicating similar PrimitiveWires signal to each other.
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
- xp as variant : Object, or string evaluation, to which the action function is defined.
- x as function : The action function.
- yp as variant : Object, or string evaluation, to which the handler function is defined.
- y as function : The hander function.
- ep as variant : Object, or string evaluation, to which the error function is defined.
- e as function : The error function.
Returns
i as String: Returns the identifier of the wire object.
[ Hemi JavaScript Framework - Stephen W. Cote, 2002 - 2011. ]