In order to better make sense of the types, I tried porting this to TypeScript - I can't make sense of the type of the dependencies property of a subscription.
Specifically, I can't make sense of these lines in the reader:
Here, subscriptions is a Set - but then you add the set of subscriptions to dependencies, which is also a Set (which gets created in createEffect) soooo... is it a Set of Sets (of Subscriptions?) or what's going on here?
I mean I have a working example in the article. I'm basically backlinking the signal because on effect re-run we have to unsubscribe from all the signals that it appears in their subscription lists. So the link has to work both ways. The Signal here doesn't have an instance really and I just needed the subscriptions so I added that. I could have made it a callback maybe for clarity. This demo isn't how Solid actually works completely. It's just a way of doing the basics with next to no code.
Yeah, the example works - I guess I have trust issues with plain JS without types. I've seen too much JS that "works", but not for the right reason, or not the way it appeared to work, if you know what I mean?
I think types would better explain the data structures and concepts here - rather than making the reader reverse engineer the code to try to infer what's what. What's running, what's in dependencies, and so on.
It's challenging even after watching the video and reading the article.
// A Dependency has many different Subscribers depending on it// A particular Subscriber has many Dependencies it depends ontypeDependency=Set<Subscriber>;typeSubscriber={execute():void;dependencies:Set<Dependency>;};
In order to better make sense of the types, I tried porting this to TypeScript - I can't make sense of the type of the
dependencies
property of a subscription.Specifically, I can't make sense of these lines in the
reader
:Here,
subscriptions
is aSet
- but then you add the set ofsubscriptions
todependencies
, which is also aSet
(which gets created increateEffect
) soooo... is it a Set of Sets (of Subscriptions?) or what's going on here?Are you sure the code is correct?
TypeScript playground link
I mean I have a working example in the article. I'm basically backlinking the signal because on effect re-run we have to unsubscribe from all the signals that it appears in their subscription lists. So the link has to work both ways. The Signal here doesn't have an instance really and I just needed the subscriptions so I added that. I could have made it a callback maybe for clarity. This demo isn't how Solid actually works completely. It's just a way of doing the basics with next to no code.
Yeah, the example works - I guess I have trust issues with plain JS without types. I've seen too much JS that "works", but not for the right reason, or not the way it appeared to work, if you know what I mean?
I think types would better explain the data structures and concepts here - rather than making the reader reverse engineer the code to try to infer what's what. What's
running
, what's independencies
, and so on.It's challenging even after watching the video and reading the article.
I still can't make sense of the types.
Sometimes clarity comes from the chosen names.
Change #1:
Change #2:
Change #3:
Change #4:
TypeScipt Playground
Yes! This is what the article/video/example was missing. Thank you! 😀🙏