Basics of Targets

Targets in TargetJS can operate independently, react to other targets, or combine both approaches. This flexibility allows developers to define simple operations as well as complex execution sequences using the same programming model.

There are three main ways to use targets:

  1. Independent execution: A target manages its own execution through built-in controls such as steps, interval, cycles, and loop, along with lifecycle callbacks such as onComplete, onValueChange, and onUpdate.
  2. Reactive execution: A target can activate other targets using activateTarget() at different stages of its lifecycle, such as onUpdate() when an execution update occurs or onComplete() when its execution finishes. However, since the vision of TargetJS is to create an assembly line based on the order of target declarations, the framework also supports two postfixes, $ and $$, appended to target names. These allow targets to automatically react to execution updates or the completion of preceding targets, without explicitly calling activateTarget().
  3. Hybrid execution: A target combines its own execution controls with reactive behavior, allowing it to respond to other targets while independently managing its own operations.

Reactive Targets: Understanding $ and $$

TargetJS uses two postfixes appended to target names to define how they react to preceding targets. These postfixes make it possible to establish execution dependencies directly through the order of target declarations.

Single $: Execution Updates

A target ending with a single $ reacts to execution updates from its preceding target. These updates can originate from the target itself, its children, or imperative operations initiated by the target. This allows dependent targets to respond continuously as execution progresses.

The example below illustrates how single $ works:

Both onUpdate() and track$ respond to execution updates from x. The step number shows the animation's progress, while the status indicates whether x is updating or has completed. Notice that the final update occurs when x becomes complete.


            onUpdate: 0 updating
            track$:   0 updating
            onUpdate: 1 updating
            track$:   1 updating
            ...
            onUpdate: 10 updating
            track$:   10 updating
            onUpdate: 1 updating
            track$:   1 updating
            ...
            onUpdate: 10 updating
            track$:   10 updating
            onUpdate: 10 complete
            track$:   10 complete
            

Double $$: On Completion

A target ending with $$ waits until the preceding execution sequence has completed before it begins. This includes waiting for dependent operations and any children created by preceding targets to complete their tasks.

For example, wait$$ can introduce a pause after an animation finishes:

wait$$: {
        interval: 2000
}

The name wait is not a special keyword in TargetJS. It is a user-defined target name. The $$ postfix controls when the target executes, while interval introduces a two-second delay.

Documentation topics