Refactor SetConstant to use a lookup table#20
Open
RealRanger wants to merge 2 commits into
Open
Conversation
SebaSOFT
approved these changes
Jun 2, 2026
Coffilhg
suggested changes
Jun 13, 2026
Coffilhg
left a comment
There was a problem hiding this comment.
That makes sense. You might also make setters perfectly safe, e.g. ProfileStore.SetConstant("AUTO_SAVE_PERIOD") would reset the value to default, like you could make the setter callback be:
AUTO_SAVE_PERIOD = function(v)
if type(v) ~= `number` then
warn(`[{script.Name}]: SetConstant "AUTO_SAVE_PERIOD" ~> A number expected, got {type(v)}; Resetting to default value of 300`)
AUTO_SAVE_PERIOD = 300
return
end
AUTO_SAVE_PERIOD = v
end
Author
Good idea; I’ve updated the setters to reflect this suggestion. Each one goes through a SafeSet utility, which enforces the type check and returns either the valid number or the default. That means even if someone bypasses SetConstant and calls a setter directly, it still goes through SafeSet and can’t corrupt the constant. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current implementation of
ProfileStore.SetConstantrelies on a long if/else chain to assign values. While it works, this approach:Solution
Refactored
ProfileStore.SetConstantto use a private lookup table (_constantSetters) scoped inProfileStore.Benefits