ReplaySubject is in a Shared Service as such :ReplaySubject<bool> userProvidesLiquidity = ReplaySubject<bool>(maxSize: 1);
And is called within one of my app's template :<div *ngIf="(sharedService.userProvidesLiquidity | async)">
.add(false)
in OnInit
it works, I am just curious whether this is the best way to do it
Stream<bool> _userProvidesLiquidityWithStart;
Stream<bool> get userProvidesLiquidityWithStart =>
_userProvidesLiquidityWithStart ??=
userProvidesLiquidity.startWith(false);
TypeError: Instance of 'minified:iV<bool>': type 'minified:iV<bool>' is not a subtype of type 'minified:oD<bool>'
if I initialise my ReplaySubject the following way :ReplaySubject<bool> userProvidesLiquidity = ReplaySubject<bool>(maxSize: 1).startWith(false);
@frankpepermans
The getter is just a workaround so that Angular doesn't go into an update loop. On each update cycle, it will invoke your subject.startWith(), this will yield a new Stream instance on every call, causing overflow. If you store the Stream as a reference, as with that getter, you can overcome that issue.
startWith()
that is responsible for such a behaviour ? I kind of expected the same instance to be returned each time as you have noticed.
_login
.map<Request>(_formRequest)
.doOnData((_) {
_attemptLogin.sink.add(true);
})
.asyncMap(Auth.login)
.doOnData((_) {
_attemptLogin.sink.add(false);
})
.listen(_userAuth.sink.add);
I can’t seem to get the latest version to execute the asyncMap()