Table of Contents

Unit

Inherits:HTMLElement

Overview

The Unit object is the core of BitsmistJS. It inherits from HTMLElement and thus takes over the functionality of a standard HTML element. When creating your own units, you create them by inheriting from this Unit class.

Properties

uniqueId

Type:String Target:Prototype get

A unique ID assigned to each instance of the unit. It is automatically generated. BITSMIST.V1.Unit static class always returns “00000000-0000-0000-0000-000000000000”.


assets

Type:Object get

The object that holds assets.


ready

Type:Promise get

The promise that is resolved when a unit is ready.

Methods

get(assetName, key, defaultValue)

Type:* Target:Prototype

Returns the value from the asset.

Parameters

ParameterTypeDescription
assetName
Required
String The asset name.
key
Required
StringThe key in the asset to be retrieved.
defaultValue*Returns this value if the specified key is not found in the asset.

Return Value

The value obtained from the asset.


has(assetName, key)

Type:Boolean Target:Prototype

Returns whether the asset has the specified key.

Parameters

ParameterTypeDescription
assetName
Required
String The asset name.
key
Required
StringThe key in the asset to be checked.

Return Value

True if the key exists, False if not.


set(assetName, key, value)

Type:Undefined Target:Prototype

Sets the value to the asset.

Parameters

ParameterTypeDescription
assetName
Required
String The asset name.
key
Required
StringThe key in the asset to be set.
value*The value to set.

Return Value

Undefined.


upgrade(unit, type, name, content)

Type:Undefined static

Upgrades the unit. The type of upgrade varies depending on the type argument.

typeDescription
“asset”Adds the asset to the unit. Specify the asset name for the “name” and content holder for the “content” parameter.
“method”Adds the method to the unit. Specify the method name for the “name” and the Function object for “the content” parameter.
“property”Adds the property to the unit. Specify the property name for the “name” and the getter/setter for the “content” parameter.
othersAdds content to the asset specified by the “name” parameter with the “content” parameter.

Paramters

ParameterTypeDescription
unit
Required
UnitThe unit to be upgraded.
type
Required
StringThe upgrade type. Valid types are “asset”, “method”, “property” and the asset names.
name
Required
StringThe name of the item to be upgraded.
content
Required
*The content of upgrade.

Return Value

Undefined.