Bitsmist Frameworks
Docs » Properties and Methods

Properties and Methods

Overview

Units, which are components of BitmistJS, inherit the standard HTMLElement, have almost no other functionality. In BitmistJS, functionality is added to units by attaching what is called a perk to the unit. Units can have additional properties and methods, but the addition of properties and methods is kept to a minimum to avoid name conflicts between the functions added by the various perks. Instead, we have a container called an asset, into which each perk will add functions. Items in assets are prefixed with a period-separated perk-specific word, such as “basic.scan”, to prevent name collisions.

There is no restriction on adding properties or methods on the library side. Prefixing is also a rule, and there is no mechanism to enforce it. It is solely up to the creator to decide whether or not to comply.

The asset provides vessels for storing various types of items. By default, there are assets called “inventory,” “vault,” “state,” “setting “skill”, and “spell” assets.

Properties and Methods

The following is a small but present list of properties and methods that the BitsmistJS core library adds to units. Each of these is considered to be used from the unit (public) and some are not considered to be used directly from the unit (private).

Although we refer to them here as public and private, there is no specific difference. You can still access them from your unit. We recommend that you do not access anything that is private.

Public

Methods are provided primarily for accessing assets.

NameDescription
set()Stores a value in an asset.
get()Get a value from an asset.
has()Checks if the specified item exists in the asset.
use()Use skill, spell in the asset.
uniqueIdThe unique ID of the unit
unitRootThe unit's node.

Private

Private properties are prefixed with __bm_. Although the library cannot prevent access to them, it is recommended that they not be used.

NameDescription
__bm_assetsThe object to store the assets.
__bm_uniqueidThe unique ID of the unit.
__bm_unitrootThe unit's node.
__bm_initializedThe flag to indicate whether the unit has been initialized.
__bm_readyThe promise to indicate whether the unit can perform initialization and termination processes.
__bm_eventinfoThe unit's event handler information.

There are also methods that are assumed to be overridden and implemented.

NameDescription
_getSettings()Returns the unit settings.

Assets

An asset is a container for various types of items. By default, there are “inventory”, “vault”, “state”, “setting”, “skill”, and “spell”.

NameDescription
inventoryThe asset to store the unit's public information.
vaultThe asset to store the unit's private information.
stateThe asset to store the information about the unit's statuses.
settingThe asset to stores the unit's settings.
skillThe asset to stores the unit's methods.
spellThe asset to store the asynchronous methods of the unit.

The set(), get(), and use() methods are provided to access items in the asset.

NameDescription
set()The method to store values in an asset.
get()The method to retrieve a value from an asset.
use()The method to use the skills and spells in the asset.

When items are added to an asset, The items in the assets are prefixed with a period-delimited, perk-specific prefix, such as “basic.scan”, to avoid name conflicts.

Inventory, Vault and State

There are three types of assets for storing information: inventory, which stores public information; vault, which stores private information; and state, which stores information about the state of the unit.

The set() and get() methods are used to access the contents of each.

this.get("inventory", "skin.skins.default");
this.set("vault", "style.applied", ["default"]);

Vault stores private information, but there is no mechanism to prevent Javascript from accessing to it. It should not be used for security purposes.

Setting

The “setting” asset is used to store settings. The items in the settings, like in other assets, are separated by a prefix for each perk.

this.get("setting", "skin.options.skinRef");

At startup, it reads and stores settings from its own _getSettings() method or from an external settings file.

For more information on settings, please see below.

  • Unit Explained - Settings

Skill and Spell

There are two assets for storing methods: “skill” and “spell”. The difference between skill and spell is that skill stores non-asynchronous methods and spell stores asynchronous methods. Spells return a promise and should be handled appropriately.

The items in skill and spell, like in other assets, are also separated by the prefix of each perk.

// Skill
let ele = this.use("skill", "basic.scan", "btn-menu");
 
// Spell
this.use("spell", "unit.materialize").then((addedUnit) => {
    addedUnit.use("spell", "dialog.open");
});
 
// or
 
await this.use("spell", "unit.materialize");
addedUnit.use("spell", "dialog.open");
Previous Next

© 2019-2023 Masaki Yasutake

Bitsmist Frameworks

Table of Contents

Table of Contents

  • Properties and Methods
    • Overview
    • Properties and Methods
      • Public
      • Private
    • Assets
      • Inventory, Vault and State
      • Setting
      • Skill and Spell

Introduction

  • Overview
  • Installation
  • Create a Sample Unit

Unit Explained

  • Overview
  • Properties and Methods
  • Settings
  • Loading
  • Events
  • HTML
  • CSS
  • Extending with Perks

Reference - Unit

  • Unit

Reference - Perk

  • Perk (Base Class)
  • BasicPerk
  • EventPerk
  • PerkPerk
  • SettingPerk
  • SkinPerk
  • StatusPerk
  • StylePerk
  • UnitPerk

Reference - Store

  • Store
  • ChainableStore

Reference - Utility

  • AjaxUtil
  • ClassUtil
  • URLUtil
  • Util