Company

About Guide API Docs Git Repo

Company API

Unit Constructor

Type: Unit

The main unit constructor.

Syntax

new Unit(descriptor);

Arguments

  1. descriptor (object) - an object containing one or more properties that will be added to the properties of the unit object. Can also include special properties (see below).

Special Properties

Returns

Function: Unit.isUnit

Checks if an object is a unit or is unit-like.

Syntax

Unit.isUnit(obj);

Arguments

  1. obj (mixed) - the object to check.

Returns

Function: Unit.decorate

Adds unit functionality to an object.

Syntax

Unit.decorate(obj, noEventWrap);

Arguments

  1. obj (object) - the object to decorate.
  2. noEventWrap (boolean; optional) - if set to true, the fireEvent method of the object (if it exists) will not be wrapped. Defaults to false.

Returns

Function: Unit.undecorate

Removes unit functionality from an object.

Syntax

Unit.undecorate(obj);

Arguments

  1. obj (object) - the object to undecorate.

Returns

Function: Unit.wrapEvents

Wraps an object’s fireEvent method to also invoke publish.

Syntax

Unit.wrapEvents(obj);

Arguments

  1. obj (object) - the object whose fireEvent method will be wrapped.

Returns

Function: Unit.unwrapEvents

Unwraps an object’s fireEvent method.

Syntax

Unit.unwrapEvents(obj);

Arguments

  1. obj (object) - the object whose fireEvent method will be unwrapped.

Returns

Unit Instance

Unit Method: setupUnit

Initializes the unit object.

Syntax

unit.setupUnit();

Arguments

Returns

Notes

Unit Method: extendUnit

Adds properties to a unit instance.

Syntax

unit.extendUnit(obj);

Arguments

  1. obj (mixed) - an object whose properties and methods will be added to the unit instance.

Returns

Notes

Unit Method: getPrefix

Returns the prefix of a unit instance.

Syntax

unit.getPrefix();

Arguments

Returns

Unit Method: setPrefix

Sets the prefix of a unit instance.

Syntax

unit.setPrefix(prefix);

Arguments

  1. prefix (string) - the new prefix for the unit instance.

Returns

Unit Method: isAttached

Checks whether a unit instance is connected to the dispatcher.

Syntax

unit.isAttached();

Arguments

Returns

Unit Method: attachUnit

Connects a unit to the dispatcher.

Syntax

unit.attachUnit();

Arguments

Returns

Unit Method: detachUnit

Disconnects a unit to the dispatcher.

Syntax

unit.detachUnit();

Arguments

Returns

Unit Method: publish

Broadcasts a message to all units.

Syntax

unit.publish(type, data, finalized);

Arguments

  1. type (string) - the type of message to be published.
  2. data (mixed, optional) - the data associated with the message that will be passed to subscribers.
  3. finalized (boolean, optional) - if set to true, the message will be broadcasted as final.

Returns

Notes

Unit Method: subscribe

Subscribes a unit to a message type.

Syntax

unit.subscribe(type, fn);

Arguments

  1. type (string) - the type of message to subscribe to.
  2. fn (function) - the function to execute when a message of the type is received.

Returns

Notes

Unit Method: unsubscribe

Unsubscribes a unit from a message type.

Syntax

unit.unsubscribe(type, fn);

Arguments

  1. type (string) - the type of message to unsubscribe to.
  2. fn (function, optional) - the function to execute when a message of the type is received.

Returns

Notes