Skip to content

Refactor RetrospectiveCorrection Initialization - #2014

Merged
ps2 merged 3 commits into
LoopKit:devfrom
loopandlearn:irc-state
Jun 28, 2023
Merged

ps2 merged 3 commits into
LoopKit:devfrom
loopandlearn:irc-state

Conversation

@bjorkert

Copy link
Copy Markdown
Contributor

This pull request solves the issue with toggling IRC On/Off without re-starting the app.

I did not want to re-create the RetrospectiveCorrection class for each evaluation or loop, therefore a new computed property retrospectiveCorrection is added in LoopDataManager. This property checks the integralRetrospectiveCorrectionEnabled flag in UserDefaults, and based on its state, it creates an instance of IntegralRetrospectiveCorrection or StandardRetrospectiveCorrection. This instance is then cached and reused unless the flag's value changes.

Two new private variables, lastIntegralRetrospectiveCorrectionEnabled and cachedRetrospectiveCorrection, have been added to support the caching mechanism.

By removing the instance creation logic from the "Static configuration" block in LoopSettings, it recognizes that this process is, in fact, not static. Moreover, the LoopSettings class adheres to the Equatable protocol, which makes it unsuitable for holding a cache of the RetrospectiveCorrection instance.

@marionbarker

Copy link
Copy Markdown
Contributor

I merged recent dev commits into this branch and proved it builds.
Next I will do more testing that IRC toggle changes state without quit/restart required.

@ps2
ps2 merged commit 42aeeb4 into LoopKit:dev Jun 28, 2023
@ps2
ps2 deleted the irc-state branch June 28, 2023 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants