Add AnyVariable as a read-only representation of Variable#697
Add AnyVariable as a read-only representation of Variable#697larryonoff wants to merge 1 commit into
Conversation
|
Hi @larryonoff , I understand why this might be convenient in some cases, and why some other libraries use similar approaches, but I wouldn't want to pull this to main repo because that would mean that we are creating parallel concept to the observable sequence that has latest value exposed. IMHO this concept is too high level for this repo. |
|
What do you think about moving this concept into RxSwiftCommunity? |
|
Hi @larryonoff , Maybe RxViewModel? It's kind of hard to me to judge where should this belong. Could you maybe more explain some of the typical use contexts of this concept? |
I think that it's better to do in a separate project. Because the concept isn't only for ViewModel, but can be used in other app architecture approaches.
The problem is that |
This doesn't seem to me like a big difference from exposing The only difference is exposing current value, but the real question is should you ever expose it, because if you are, then you have 2 ways of fetching a value, and you need to define an sensible initial value for all values, which might not be possible to always do. Did you maybe check out |
I absolutely agree and you have a very good point. Let me rephrase my idea then. Immutable |
|
Hi @larryonoff ,
right, but if you have only one thing that changes a value, then you can might as well just propagate that original observable and be done with it :) Like you've said, the difference is if you want to communicate no effects are performed. In that case specific type could be used, similar to Variable/BehaviorSubject, but without value. I think this is similar to #771 and #731. We might want to just create a repo in RxSwiftCommunity and add these concepts into it. |
|
Is maybe this kinda solving your problem? (just declaring the Variable class as a struct): In this way, declaring: Allows you to change the Variable value from inside the viewModel but not from outside. (just an idea, could not fully test the problems of making it a struct yet due to lack of time) (maybe a mix between this and @larryonoff code is the way to go) |
|
@acecilia Thanks! But how it differs from code in my PR? |
|
I do not quiet see how your PR works, from what I understood you still will need to declare a Variable to emit the objects that go into the observable of the AnyVariable (right?) |
The reason why I need this functionality:
AnyVariablecan be initialized on init and is used to avoid unsafe mutability after.Code I have right now:
Please see this PR.
PS
I'll proceed with this PR if it's accepted.
I also suggest renaming
VariabletoMutableVariable.