You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey! First of all - amazing library! I'm just looking over at these utilities and they look really strong! Some are things I had implemented myself (but your implementation is better) and some are things I haven't even thought that I need!
I had an idea that might fit your library (if it doesn't - no problem).
functionwaitForSignal<T,UextendsT>(value: Signal<T>,filter: (value: T)=>value is U,): Promise<U>;
An example use-case would be if you have a signal with a loading state, but you want to wait for a loaded value:
exportfunctioninjectWaitForSignal(){constinjector=inject(Injector);returnfunctionwaitForSignal<T,UextendsT>(value: Signal<T>,filter: (value: T)=>value is U,){returnnewPromise<U>((resolve)=>{consteffectRef=effect(()=>{constv=value();if(filter(v)){resolve(v);effectRef.destroy();}},{
injector,},);});};}
I wrapped it in an injection function, because a) I need an injection context, and b) it's unlikely that the consumer will have that injection context when they want to call it, if there are multiple awaits. I feel like that simplifies things for the consumer as they can call it in the beginning and then use the function as many time as they want.
The text was updated successfully, but these errors were encountered:
ShacharHarshuv
changed the title
Feature Suggestion: awaitForSignal
Feature Suggestion: waitForSignal
Jul 31, 2024
Hey! First of all - amazing library! I'm just looking over at these utilities and they look really strong! Some are things I had implemented myself (but your implementation is better) and some are things I haven't even thought that I need!
I had an idea that might fit your library (if it doesn't - no problem).
An example use-case would be if you have a signal with a loading state, but you want to wait for a loaded value:
Here's an example implementation of this:
I wrapped it in an injection function, because a) I need an injection context, and b) it's unlikely that the consumer will have that injection context when they want to call it, if there are multiple awaits. I feel like that simplifies things for the consumer as they can call it in the beginning and then use the function as many time as they want.
The text was updated successfully, but these errors were encountered: