Sleitnick / rbxts-clack

User input helper classes
https://www.npmjs.com/package/@rbxts/clack
MIT License
1 stars 1 forks source link

Prefer class #4

Closed Sleitnick closed 2 years ago

Sleitnick commented 2 years ago

The Prefer module was turned into a class instead of standalone functions. This is due to the need for a connection to UserInputService.LastInputTypeChanged at the root of the functionality. With just a list of functions, this event had to be connected within the root of the module code, which was not possible to disconnect. This is problematic for testing code. By wrapping it in a class, the event will only be connected if the class is instantiated, and offers a destroy method to disconnect the event.

Sleitnick commented 2 years ago

An alternative would be to have another function that acted as a "startup" for the module's functionality. This, however, would feel unordinary. Thus, adding a class seemed to be the most ergonomic decision.