Identifiers
Identify a listener function call based on its call stack 🕵️
A listener identifier is an array of strings representing the current call stack in reverse chronological order (newest first).
Listener functions receive a listener identifier (lid
) as the first argument.
Identifiers are mainly used to target listener bindings, but have other potential uses.
Pass the identifier along
Here we show how listener functions pass the lid
along to the next listener function.
① Create a library with listeners that call each other and save it as lidExample.ts
:
The identifier array is immutable and remains the same value for the scope of the function.
② Load the listener, call the listener function, and save it as main.ts
:
③ Execute main.ts
and view the output:
Custom identifiers
Its not heresy to simply prepend your own id to the lid
as you pass it along:
Automatic unique identifiers
By changing lid
to lid_
, we signal for listener to prepend a unique identifier to the listener function call:
Unique identifier is a misnomer; the identifier is more like an alphanumeric counter that produces ids in the same order with each new execution.
Last updated