Dusty
Dusty
SSolidJS
Created by Dusty on 12/9/2023 in #support
Suspending or creating a resource from a Signal
I'm new to solid and trying to integrate it with Dexie. I looked at solid-dexie (https://github.com/faassen/solid-dexie) but I have a couple issues with it so I'm exploring taking it in my own direction. One problem, however, has me stumped. Dexie exports an observable that is easy to link into with from. My issue is that there is a (very short) period between when the signal is defined and when it actually has a value. After that, it's guaranteed to have a value, and the signal fires repeatedly thereafter whenever the db content updates. This means that I have to litter my code with <Show> tags to check if each Dexie query I make actually has content. If only there was a way I could wait for all my signals to have content before I render anything. Enter Suspense, or so I thought. My problem is that the Dexie queries aren't really a resource (they are signals that can fire multiple times, whereas a resource fires only on demand). I'm not clear if it's safe or sane to return a signal from a resource, but it seems to lack elegance. So I checked the createResource source code and decided that I really just need to increment and decrement the suspense context at just the right time. The problem with that idea is that a very intelligent person realized that it would be imprudent to allow yahoos like me to increment and decrement the suspense context. Therefore getSuspenseContext isn't exported. Soooo... I'm looking for advice. Is there an elegant way to tie an observable signal to suspense using createResource or otherwise?
32 replies