SolidJSS
SolidJS10mo ago
9 replies
gsoutz

How to test for is loaded for a create async source change

In the real world example there are these methods that loads some async data:

    loadArticles(predicate) {
      setArticleSource(["articles", predicate]);
    },
    loadArticle(slug) {
      setArticleSource(["article", slug]);
    },


https://github.com/solidjs/solid-realworld/blob/main/src/store/createArticles.js

Here's what async resource looks like in my case:

  const replay_tree = createAsync<ModelReplayTree>(async () => {
        let s = source()
        if (!s) {
            return default_replay_tree()
        }
})


I have 2 questions: when you do this:

let [pending, start] = useTransition()
  start(async foo() => { return 30 })


is pending, waiting for foo to finish, or does it also include any triggered createAsync's as well.
Because as I tested before it always returned true to me before loading this async resource I don't know why.

Second:

In this real world example, how would I get notified when the articles finished loading after I call
loadArticles() or loadArticle().
Maybe the real world example is outdated because it uses createResource, but it's the only example that I adopted changing it to createAsync in my case. But I still would like to know when the articles are ready to show.

Sometimes even though an old value is loaded, I want to load it again to get a fresh copy because I made some changes in the old copy. So I can't just test the id to be equal to requested id. Which how I used to check for loaded.
Please notify me if this example is bogus, because it does use some tricks I think is pretty weird.
GitHub
A Solid Implementation of the Realworld Example App - solidjs/solid-realworld
solid-realworld/src/store/createArticles.js at main · solidjs/solid...
Was this page helpful?