Nemokosch
Nemokosch
Explore posts from servers
SIASapphire - Imagine a framework
Created by Nemokosch on 8/5/2024 in #sapphire-support
Statefulness and data sharing for Pieces
Hi, let's imagine the following: you want to keep track of some data about the people who join and leave a certain voice channel. It would be convenient to store this data alongside the listener and maybe provide an interface to it directly from the listener. However, it's not fully clear how and when Pieces are instantiated. There are no examples of holding (let alone sharing) any state. How to do this right? 1. is it okay to hold state in a Listener instance? 2. if so, how to access the very same instance somewhere else? 3. if not, what to do instead? Exposing all that data via the container sounds quite painful because that's very far from encapsulated. What would you do to expose some data managed by a certain event handler?
52 replies