Flo
Flo

Reputation: 66

Is there a pattern for signals with arguments?

With the recent blow up of signals in almost every major js ui framework, there is one part of it I don't fully understand: Say for example one wants to create signals for cached Rest queries.

My naive approach would be to store a map of the queried entity ids mapped to a signal wrapping the result of that query. I would then use a function that abstracts away the map looking like: getFoo(id): Signal<Foo> that also adds a new signal to the map in case it doesn't yet exist. Although it does work, it feels very verbose to write so much that I am wondering why that is not part of the signal library itself or at least of a companion package. Is there a better way to do something like that? Am I maybe using signals wrong? I just wanted to hear your opinions on this. Maybe I am a bit spoiled by riverpods family providers.

Upvotes: 0

Views: 52

Answers (0)

Related Questions