twostraws / ControlRoom

A macOS app to control the Xcode Simulator.
MIT License
5.75k stars 306 forks source link

Moved some UserDefaults outside of Preferences to avoid unnecessary .body computations #113

Closed laclouis5 closed 3 years ago

laclouis5 commented 3 years ago

Discussion in issue https://github.com/twostraws/ControlRoom/issues/107.

I moved some UserDefaults outside of Preferences class because they should be local state of some views instead of global shared state (e.g. filterText, carrier). I used @AppStorage for memory persistence accros launches.

For filterText I made the filterSimulator() func of SimulatorsController public to be able to update the list when filterText changes.

I also removed some useless .environmentObject(preferences) calls since it was already called higher in the view tree.

There are still some UserDefaults that could be removed from Preferences I think.

All those changes avoid lots of .body computations that were uselessly triggered by the many Preferences updates triggered by keystrokes (in URL and Carrier fields for instance) and updating the simulators list view.

twostraws commented 3 years ago

This is really great work – thank you very much!