Class Index | File Index

Classes


Class R.components.logic.Notifier


Extends R.components.Logic.
A component which notifies objects when an action occurs. The component uses a subscriber model to notify an object when certain actions occur. This component can be used so that multiple objects could subscribe to one to be notified when a particular event occurs. The objects don't have to exist within the same scope.

For example, a host object could publish an event of type "death" that other hosts are listening for. Thus, when the host dies, it can pass relevant information that other objects (such as a life counter) could respond to. Rather than the host having to actively know about other parts of the game world, those other objects could "listen in" on the actions of the host and act accordingly.
Defined in: notifier.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
R.components.logic.Notifier(name, priority)
Create a notifier component
Fields borrowed from class R.components.Base:
TYPE_COLLIDER, TYPE_INPUT, TYPE_LOGIC, TYPE_RENDERING, TYPE_TRANSFORM
Method Summary
Method Attributes Method Name and Description
 
Destroy the component instance
 
Get the class name of this object
 
post(type, eventObj)
Post a message of the given type, with the event object which subscribers can act upon.
 
Releases the component back into the object pool.
 
subscribe(type, fn, thisObj)
Subscribe to the event type specified, receiving a subscriber Id in return.
 
unsubscribe(type, subscriberId)
Unsubscribe from the event type specified.
Methods borrowed from class R.components.Base:
execute, getGameObject, getHostObject, getPriority, getType, getTypeString, setGameObject, setHostObject, setPriority
Methods borrowed from class R.engine.BaseObject:
addEvent, addEvents, getElement, jQ, removeEvent, setElement, triggerEvent, update
Methods borrowed from class R.engine.PooledObject:
clearObjectDataModel, getId, getName, getObjectDataModel, getProperties, isDestroyed, setName, setObjectDataModel, toString, toXML
Class Detail
R.components.logic.Notifier(name, priority)
Create a notifier component
Parameters:
name
{String} The name of the component
priority Optional, Default: 1.0
{Number} The priority of the component
Method Detail
destroy()
Destroy the component instance

{String} getClassName()
Get the class name of this object
Returns:
{String} "R.components.logic.Notifier"

post(type, eventObj)
Post a message of the given type, with the event object which subscribers can act upon. The event object is free-form and can contain anything. The subscribers should know what to look for and how to interpret the event object being passed to them.
Parameters:
type
{String} The type of the event
eventObj
{Object} An object which subscribers can use

release()
Releases the component back into the object pool. See R.engine.PooledObject#release for more information.

{String} subscribe(type, fn, thisObj)
Subscribe to the event type specified, receiving a subscriber Id in return. When the event type is posted, the specified callback will either be called in the scope of thisObj, or if thisObj is null then the scope will be this component's host object.

Any object can subscribe to any other object's events. This is a handy method to use event passing as a way to propagate actions from one object to a group of other objects.

Parameters:
type
{String} The type name of the event.
fn
{Function} The function to call when the event triggers.
thisObj Optional
{Object} The object which will represent "this" for the callback.
Returns:
{String} A subscriber Id which can later be used to unsubscribe

unsubscribe(type, subscriberId)
Unsubscribe from the event type specified. If you only pass the event type, all subscribers will be removed for that type. Passing the optional subscriberId will unsubscribe a specific subscriber.
Parameters:
type
{String} The event type to unsubscribe from
subscriberId Optional
{String} The subscriber Id which was returned from #subscribe

Documentation generated by JsDoc Toolkit 2.4.0 on Mon Mar 18 2013 16:09:16 GMT-0400 (EDT)