-
-
Notifications
You must be signed in to change notification settings - Fork 879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle observable()
w/o getOwner
#1115
Conversation
Pull Request Test Coverage Report for Build 2668977635
💛 - Coveralls |
Updates the observable() function to support usage outside a Solidjs context. Also updates ObservableObserver to make the "next" property in an observer object optional to align with RXJS. fixes solidjs#1110
// properly typed for 3rd party library's like RXJS. | ||
declare global { | ||
interface SymbolConstructor { | ||
readonly observable: symbol; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the comment above this interface suggests, ensuring that a type for Symbol.observable
exists is necessary for Solid's observable()
function to be properly typed for RXJS (and I imagine other observable library's as well). This is because RXJS's from()
function expects an object with { [Symbol.observable](): Subscribabble<T> }
. Previously, getSymbol()
didn't return Symbol.observable
but instead returned any
which breaks type interoperability.
Looks good. Thank you. |
I do have one more thought here. Disposal is tied to the context where the subscription happens being cleaned up, but I'm sort of wondering if the disposal should tied to the observable wrapper itself. Very much like we were talking about it maybe should be a single computed. It really could go either way because it's the hot versus cold thing. But Solid is Hot, and perhaps we should treat our Observables here as hot too, basically they are Subjects rather than Observables. @jorroll do you have an opinion. |
Ya, I thought about that in the context of creating an observable that shares a single computed. My example SolidObservable potentially changed the Solidjs
Correct me if I'm wrong, I was thinking that a "hot" observable is one that has a side-effect/does some work when the observable is created whereas a "cold" observable just has a side effect/does some work when it is subscribed to. With this definition, hot vs cold doesn't necessarily enter this discussion. For example the SolidObservable implementation I wrote for "an observable which shares a single computed" doesn't create that computed when the observable is created. Instead, that
I'm interpreting this question as "should the observable capture the owner when it's created or should it capture the owner at subscription time" and honestly I'm not really sure. I can see it going either way. But if I had to pick one, capturing the owner at observable creation time seems like it will probably be the least surprising to the most people. |
I agree with pretty much everything you've said here. Yeah doing creation lazily is better in terms of creation. I use the hot/cold pretty loosely I suppose, similar to Andre Staltz' justification for creating XStream. In any case I think that approach is probably the correct approach. And the direction this should go ultimately. Thank you for confirming this. |
Ah, from the article:
In this case, and with deciding to capture the
👍 |
Updates the
observable()
function to support usage outside the Solidjs context. Also updatesObservableObserver
to make the "next" property in an observer object optional to align with RXJS'sSubscribable
interface (which is what RXJS'sfrom()
expects). At the moment,from(observable(mySignal))
results in a type error (assumingfrom()
is imported from RXJS).Summary
Fixes #1110
I'll note that the "Before submitting a pull request" instructions include "Format your code with prettier" yet the Solidjs repo doesn't include a formatting script nor is prettier listed as a devdependency? I attempted to run
yarn prettier
but since prettier wasn't available I gave up.How did you test this change?
I reimplemented the
observable()
function in my React app using this solution.