Skip to content

Behavior

class

Back to Helios Web API

Kind
class
Source
src/behaviors/Behavior.js:33

Description

Base class for reusable Helios application behaviors.

Signature

export class Behavior extends EventTarget {

Parameters

NameTypeAttributesDefaultDescription
optionsObjectoptionalSerializable configuration owned by the behavior.

Returns

Detached behavior instance; Helios attaches it through helios.useBehavior(...) or BehaviorManager.use(...).

Type Behavior

Notes

Behaviors attach to a Helios context, own serializable state, emit change events, and register cleanup hooks for listeners, timers, and UI bindings. Custom behaviors should override attach, detach, serialize, and restore only where needed.

Instance Properties

id

Source: src/behaviors/Behavior.js:34

Id exposed by the class.

Network And Persistence

Network replacement, serialization, and visualization state persistence. ExporterBehavior and InterfaceBehavior can surface parts of this flow in the UI.

attach(context)

Source: src/behaviors/Behavior.js:44

Configures or reads attach.

Parameters

NameTypeAttributesDefaultDescription
contextValue passed to attach.

serialize()

Source: src/behaviors/Behavior.js:69

Handles serialize for the current graph or visualization state.

restore(snapshot = {}) → {this}

Source: src/behaviors/Behavior.js:73

Updates the restore state on the current instance.

Parameters

NameTypeAttributesDefaultDescription
snapshotoptional{}Value passed to restore.

Returns

This instance.

Type this

Events

Event subscription helpers and emitted interaction events.

emit(type, detail)

Source: src/behaviors/Behavior.js:91

Configures or reads emit.

Parameters

NameTypeAttributesDefaultDescription
typestringAttribute value type.
detailEvent payload passed to listeners.

on(type, handler, options)

Source: src/behaviors/Behavior.js:96

Configures or reads on.

Parameters

NameTypeAttributesDefaultDescription
typestringAttribute value type.
handlerFunctionCallback invoked for the registered event.
optionsObjectOptions object for this operation.

Utilities

Additional public helpers that do not belong to a narrower API area.

detach()

Source: src/behaviors/Behavior.js:49

Manages detach for the current instance.

update(options = {}) → {Object|this}

Source: src/behaviors/Behavior.js:62

Read or set the update setting.

Parameters

NameTypeAttributesDefaultDescription
optionsObjectoptional{}Options object for this operation.

Returns

Current update value when called without arguments; otherwise this instance for chaining.

Type Object|this

Example


helios.update({
  enabled: true,
});

addCleanup(cleanup) → {this}

Source: src/behaviors/Behavior.js:80

Manages cleanup for the current instance.

Parameters

NameTypeAttributesDefaultDescription
cleanupValue passed to addCleanup.

Returns

This instance.

Type this

removeCleanup(cleanup)

Source: src/behaviors/Behavior.js:86

Manages cleanup for the current instance.

Parameters

NameTypeAttributesDefaultDescription
cleanupValue passed to removeCleanup.

Example

class PulseBehavior extends Behavior {
  static id = 'pulse';
  attach(context) {
    super.attach(context);
    const timer = setInterval(() => context.helios.requestRender(), 500);
    this.addCleanup(() => clearInterval(timer));
    return this;
  }
}