Interface for non-mutating functions on Observable #6914
ArdorDeosis
started this conversation in
Ideas / Feature request
Replies: 2 comments
-
To keep encapsulation, the return type of |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yeah, so turns out I was just too stupid to read the documentation correctly and mixed some things up... So this can be closed, sorry for that. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
edit: turns out I did mix some stuff up when I was reading the docs and this is obsolete since the observable class does not expose the mutating features.
I'd like to make a case for an interface (or interfaces) that contain non-mutating functions on anObservable
that are meant to be used by a consumer. My concrete case is for the.pipe()
method.I found this (closed) PR about a similar topic, which was missing a (imo crutial) use case: encapsulationExample CaseI have aServiceImplementation
implementing aServiceInterface
. The implementation is using anObservable
internally. I want other services (consumers) to be able to subscribe to it, but they should not be able to call.next()
(or.complete()
or.error()
) on it. They should only be able to observe, not change the state or fire events. This can be achieved by only exposing aSubscribable
inServiceInterface
, but then consumers cannot use the.pipe()
operator (which is defined onObservable
). If I however expose the wholeObservable
, all consumers could call.next()
, which should only happen from within myServiceImplemntation
.For the moment I can create my own type or interface by copying the pipe signatures from the source, but this is not really maintainable, it will break whenever there are signature changes in RxJS. I think an interface containing.pipe()
(and other non-mutating methods) would help here.Beta Was this translation helpful? Give feedback.
All reactions