-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Change defaults with Local<> to be more ergonomic #17747
Copy link
Copy link
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-DocsAn addition or correction to our documentationAn addition or correction to our documentationD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-DocsAn addition or correction to our documentationAn addition or correction to our documentationD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!
What problem does this solve or what need does it fill?
I often use Local for systems that keep track of local ui input, timers, counters, etc. For data that only needs to be accessed in a single system, it's very convenient especially for prototyping to not have to manage resources or components. Using Local<> with a default value however is a lot more complex and makes Local<> much less appealing to use. The workaround described in the docs is to use a resource and convert your system into a capturing closure, which is more complex.
What solution would you like?
A possible solution would be a function on Local<> to set an intial value that is only in the first run of the system.
Example:
What alternative(s) have you considered?
An alternative workaround is to create a wrapping type, and impl default on that type, then Local. This is still simpler than the closure solution, and makes more sense, but I feel this can be simplified further.
Example:
Additional context