StringTune/Docs

Custom Modules

Lifecycle Hooks

Accurate map of which module hooks run, in what phase, and which ones are object-specific versus global.

Lifecycle Hooks

StringTune exposes many hooks on StringModule, but not all of them are equally important, and not all of them are dispatched in the same way.

This page describes the current runtime behavior, not the theoretical interface.

Registration hooks

These run once per module instance:

HookWhen it runsTypical use
onSubscribe()immediately after stringTune.use(...) registers the modulesubscribe to global event channels
onInit()during stringTune.start(...) after the runtime startsone-time setup that needs the runtime to be alive
onUnsubscribe()during runtime teardownremove global subscriptions
destroy()after unsubscribe during teardownclear module-owned state

Object hooks

These run per connected StringObject:

HookWhen it runsTypical use
initializeObject(...)when the object is first processed or refreshedmap attributes and seed per-object state
calculatePositions(...)after initialization and on rebuild pathsderive geometry, ranges, and cached values
onObjectConnected(...)on first connection to that objectattach listeners, apply initial output
onObjectDisconnected(...)when the object is removed from the modulecleanup object-owned side effects
enterObject(...)when the object becomes entered or activemaintain hot-path collections
exitObject(...)when the object leaves active scopemaintain hot-path collections

The default connectObject(...) implementation already calls onObjectConnected(...) only on the first connection.

Frame and interaction hooks

These are the hooks you will use most often:

HookRuntime phaseReceivesBest for
onFrame(data)every frameStringDatapure computation and state updates
onScroll(data)when scroll changedStringDatascroll-dependent bookkeeping
onScrollMeasure(data)scheduled read phase after scroll changesStringDatalayout reads tied to scroll
onMouseMove(event)every mouse moveMouseEventcursor-driven target updates
onMouseMoveMeasure(data)scheduled read phase after mouse moveStringDatapointer-related DOM reads
onMutate(data)mutate phase inside a styleTxn batchStringDataDOM writes, CSS vars, inline styles
onWheel(event)wheel inputWheelEventwheel-specific behavior separate from scroll

Resize and system hooks

HookWhen it runsNotes
onResize()layout rebuild pathuse for per-object recalculation that is not already handled in initializeObject(...)
onResizeWidth()width changed or forced resizeuseful for responsive-only recalculation
onSettingsChange()after setupSettings(...) changescurrent runtime calls it with no payload
onDirectionChange()scroll direction changedcurrently dispatched
onScrollStart()scroll beginscurrently dispatched
onScrollStop()scroll stopscurrently dispatched
onAxisChange()reserved hookpresent on base class
onDeviceChange()reserved hookpresent on base class
onScrollConfigChange()reserved hookpresent on base class
onDOMMutate(added, removed)DOM observer sees mutationsuseful for sidecar scanning
onDOMRebuild()object manager rebuilds all modules after DOM workcurrent runtime dispatches this from ObjectManager

Important current-runtime caveats

Two details matter when writing real custom modules:

  • onSettingsChange() is currently called without the internal change payload. If you need detailed width, height, or scroll-height flags, the module hook does not receive them.
  • onScrollDirectionChange() exists on the base class, but the current runtime does not dispatch it. Use onDirectionChange() instead.

Which hook should own which work

Use this rule of thumb:

  • initializeObject(...) for parsing and caching object state
  • calculatePositions(...) for geometry math
  • onFrame(...) for cheap pure computations
  • onScrollMeasure(...) and onMouseMoveMeasure(...) for DOM reads
  • onMutate(...) for DOM writes
  • onObjectConnected(...) and onObjectDisconnected(...) for listener and observer management

If a module mixes reads and writes into onFrame(...), it will usually work at first and then degrade as more objects are added.