You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Version: 3.1.5
Related (old) issue: #1748 (discussing Subject.toSerialized() for v 1.x)
In my use-case, I have several Subjects; some model state (BehaviourSubject) and some events (PublishSubject). Both, new states and new events, may result from different threads. According to the docs, it is advised to call Subject.toSerialized() then, which returns a SerializedSubject (as Subject), wrapping the original subject.
This isn't ideal for me out of three reasons:
I loose the original subject's signature, for example BehaviousSubject.getValue().
Having only Subjects, the distinction between Replaying one, all or none of the previous events, will be clear only from the docs or some other context, but not from the subject's type itself.
The need to call toSerialized() isn't obvious; it's in the docs, but it would be better (and more convenient) to have it in the Subject's signature, for example BehaviourSubject.createSerialized() → BehaviourSubject. This would make the distinction clear as soon as the IDE of choice provides the auto-completion for available methods.
For the implementation I'd suggest to move away from the SerializedSubject, but compose it's synchronization inside the respective original subjects, if created as serialized subject. For the API this would be transparent, as currently only Subject is returned and returning the original subject's type from toSerialized()would not break this.
The text was updated successfully, but these errors were encountered:
getValue() is thread-safe thus if you keep the BehaviorSubject next to the SerializedSubject, you can still get to it.
This can't be reasonably encoded in types. Again, if you need this information, keep it around the subject.
This is a general issue of things that have to be learned once. No clever type signatures or API can help if those have to be learned about too. People don't read docs and don't tend to scroll through a lot of methods.
but compose it's synchronization inside the respective original subjects
No. This has been discussed before. If you are emitting from the same thread, the serialization is an overhead for no good reason.
Version: 3.1.5
Related (old) issue: #1748 (discussing Subject.toSerialized() for v 1.x)
In my use-case, I have several Subjects; some model state (
BehaviourSubject
) and some events (PublishSubject
). Both, new states and new events, may result from different threads. According to the docs, it is advised to call Subject.toSerialized() then, which returns aSerializedSubject
(asSubject
), wrapping the original subject.This isn't ideal for me out of three reasons:
BehaviousSubject.getValue()
.Subject
s, the distinction between Replaying one, all or none of the previous events, will be clear only from the docs or some other context, but not from the subject's type itself.BehaviourSubject.createSerialized() → BehaviourSubject
. This would make the distinction clear as soon as the IDE of choice provides the auto-completion for available methods.For the implementation I'd suggest to move away from the
SerializedSubject
, but compose it's synchronization inside the respective original subjects, if created as serialized subject. For the API this would be transparent, as currently onlySubject
is returned and returning the original subject's type fromtoSerialized()
would not break this.The text was updated successfully, but these errors were encountered: