WarFrontIO / client

Real-time strategy game played in the browser
https://dev.warfront.io
MIT License
20 stars 6 forks source link

Listener priorities #5

Closed platz1de closed 2 months ago

platz1de commented 3 months ago

Listeners (especially setting listeners) should have an option to manipulate the order they are called in.

Justification

In a lot of scenarios listeners can depend upon each other, e.g. when working with themes. Listener A and B depend on the values Listener C provides (e.g. C loads the shaders a new theme defines)

Currently there is no built-in way to ensure that listener C is called first, requiring listener A and B calling a method to load C if it wasn't already

Proposal

To not be limited to a fixed amount of priorities (FIRST, NORMAL, LAST), which introduce a lot of magic loading order issues, the order could use actual dependencies

For example

- export function registerListener(listener: func) { ... }
+ export function registerListener(listener: func, ...after: func[]) { ... }

Then the following would cause a to be called first, then b, then c

registerListener(b, a, c);
registerListener(a);
registerListener(c, a);

Circular dependencies do not need to be supported

platz1de commented 2 months ago

Marking as wontfix. The cases where this would be useful can be better solved by providing a new Listener from the dependend-on class. Third party code (which might require actions after listener handles) gets loaded after the normal game code and as such always registers listeners after the normal game listeners, so no change is needed here