4.4 KiB
@theatre/dataverse / Ticker
Class: Ticker
The Ticker class helps schedule callbacks. Scheduled callbacks are executed per tick. Ticks can be triggered by an external scheduling strategy, e.g. a raf.
Table of contents
Constructors
Properties
Accessors
Methods
Constructors
constructor
• new Ticker(_conf?
)
Parameters
Name | Type |
---|---|
_conf? |
Object |
_conf.onActive? |
() => void |
_conf.onDormant? |
() => void |
Defined in
Properties
__ticks
• __ticks: number
= 0
Counts up for every tick executed. Internally, this is used to measure ticks per second.
This is "public" to TypeScript, because it's a tool for performance measurements. Consider this as experimental, and do not rely on it always being here in future releases.
Defined in
Accessors
dormant
• get
dormant(): boolean
Whether the Ticker is dormant
Returns
boolean
Defined in
time
• get
time(): number
The time at the start of the current tick if there is a tick in progress, otherwise defaults to
performance.now()
.
Returns
number
Defined in
Methods
offNextTick
▸ offNextTick(fn
): void
De-registers a fn to be called on the next tick.
Parameters
Name | Type | Description |
---|---|---|
fn |
ICallback |
The function to be de-registered. |
Returns
void
See
onNextTick
Defined in
offThisOrNextTick
▸ offThisOrNextTick(fn
): void
De-registers a fn to be called either on this tick or the next tick.
Parameters
Name | Type | Description |
---|---|---|
fn |
ICallback |
The function to be de-registered. |
Returns
void
See
onThisOrNextTick
Defined in
onNextTick
▸ onNextTick(fn
): void
Registers a side effect to be called on the next tick.
Parameters
Name | Type | Description |
---|---|---|
fn |
ICallback |
The function to be registered. |
Returns
void
See
- onThisOrNextTick
- offNextTick
Defined in
onThisOrNextTick
▸ onThisOrNextTick(fn
): void
Registers for fn to be called either on this tick or the next tick.
If onThisOrNextTick()
is called while Ticker.tick()
is running, the
side effect will be called within the running tick. If you don't want this
behavior, you can use onNextTick()
.
Note that fn
will be added to a Set()
. Which means, if you call onThisOrNextTick(fn)
with the same fn twice in a single tick, it'll only run once.
Parameters
Name | Type | Description |
---|---|---|
fn |
ICallback |
The function to be registered. |
Returns
void
See
offThisOrNextTick
Defined in
tick
▸ tick(t?
): void
Triggers a tick which starts executing the callbacks scheduled for this tick.
Parameters
Name | Type | Description |
---|---|---|
t |
number |
The time at the tick. |
Returns
void
See
- onThisOrNextTick
- onNextTick