#When to use resource?

5 messages · Page 1 of 1 (latest)

fickle ember
#

So I have a questions would this be considered a good paractice to use resource to deal with async function that returns data instead of trying to use them in computed or is the purpose more about fetching one request that is a Promise ?

north hill
#

if it solves your problem and simplifies your architecture, you're fine to use it i guess.
It allows an async operation to be used inside a signals flow.

  • run an operation whenever a signal has changed
  • have a state for that operation like isLoading, hasValue, and error as signals
    it's up to you whether you use the state in a further computed signal or just directly use it in a template or don't use it at all. Although, if not using the state, you can just use an effect instead. Whatever you prefer.
fickle ember
#

@north hill thanks you for your quick answer do you have any links or official discussion that go in your direction or is it just personal deduction?

scenic bone
#

resource is basically a computed but for async.

fickle ember
#

@scenic bone thanks for the clarification