1.7 KiB
The stateManager.once() method
This documents the stateManager.once() method.
There are multiple parameters for this method, and a deeper dive into each of them can be found in the Events -> Introduction page and all of the pages within the Events category.
How is this different from stateManager.on()?
Generally, the format is just:
taClient.stateManager.once('eventType', () => {
// callback function
})
or
async function handleEvent(params) {
// code here
}
taClient.stateManager.once('eventType', handleEvent);
Essentiallly both are the same thing. The point is that when an event happens, depending on your subscription type, different types of data will be passed through to a method(callback). The reason why once() is different is because it automatically detaches after the first event. That means the callback method is only triggered once, and then the listener is removed.
The listener also detaches upon a disconnect from the CoreServer.
Its events
The events in once() are the exact same as in on(). There is no direct implementation in ShyyTAUI, as there really is not a scenario when you want a listener to only trigger once.
You might wonder why that is. Why is it not enough to listen to a matchDeleted event once? The answer is simple. Since just like on(), once() also gets triggered by other tournaments' data changes and not just the current match getting deleted.