Skip to content

Mutable properties in an Environment #505

Answered by mbrandonw
mluisbrown asked this question in Q&A
Discussion options

You must be logged in to vote

We don't think mutable state in an environment dependency is a bad thing! In fact, that's what the environment is for!

For example, if you wrote a nice wrapper around UserDefaults and put that in your environment then you've immediately got global shared state. Same if you have a dependency wrapper around file access. Or if you have a database dependency.

And so the API client having a little shared mutable data to represent the current session, such as an access token, current user, or in your case account id, is totally fine.

And as @jasdev pointed out, this is exactly what we do in isowords. The "live" API client holds a mutable currentPlayer (it's also backed by user defaults, but tha…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@jasdev
Comment options

Comment options

You must be logged in to vote
1 reply
@lordzsolt
Comment options

Answer selected by mluisbrown
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants