ReactiveX / rxdart

The Reactive Extensions for Dart
http://reactivex.io
Apache License 2.0
3.36k stars 271 forks source link

refactor(subject): `Subject.stream` now returns a read-only `Stream` #699

Closed hoc081098 closed 1 year ago

hoc081098 commented 1 year ago
codecov-commenter commented 1 year ago

Codecov Report

Merging #699 (b1b7030) into master (1a8fcef) will decrease coverage by 0.59%. The diff coverage is 56.86%.

@@            Coverage Diff             @@
##           master     #699      +/-   ##
==========================================
- Coverage   93.74%   93.14%   -0.60%     
==========================================
  Files          77       77              
  Lines        2334     2378      +44     
==========================================
+ Hits         2188     2215      +27     
- Misses        146      163      +17     
ryanheise commented 1 year ago

I would prefer to leave this sort of thing the responsibility of static type checking. Adding defensive programming here increases the binary size and slightly adds to the computation time, whereas static type checking serves the same purpose but costs nothing at runtime.

What I mean regarding the static typing is that the return type of Subject.stream is already ValueStream<T> and so it already restricts the visible interface to the intended one. If a client does try to override the static types at runtime by casting that return type to some undocumented implementation type, it is using undocumented behaviour in which case the library is no longer responsible for perils the client suffers. There is no need to add executable code to defend against clients that try to bypass the declared static types.