runWithOwner / runWithListener support tracking asynchronously #1494
Replies: 3 comments
-
Another way to do this |
Beta Was this translation helpful? Give feedback.
-
For the curious createAsyncEffecthttps://playground.solidjs.com/anonymous/a48ce634-20d1-4d28-a90f-6cb009a36fd7 function createAsyncEffect(fn) {
let v = undefined;
const run = async () => (v = await fn(v, { track }));
let track = createReaction(run);
run();
} and used like createAsyncEffect(async (prev, { track }) => {
console.log("waiting ...");
await delay(1);
track(() => count());
console.log({ current: count(), prev });
return count();
}); the
can comperable code with createEffect(async ()=>{
let l = getListener()
console.log("waiting ...");
await delay(1);
runWithListener(l, () => count())
console.log({ current: count(), prev });
return count();
}) |
Beta Was this translation helpful? Give feedback.
-
I love your createEffect(async (prev) => {
console.log("waiting ...")
return runWithTracking((track) => {
await delay(1)
console.log({ current: count(), prev })
return track(() => count())
})
}) |
Beta Was this translation helpful? Give feedback.
-
1 reason to support
runWithListener
is the ability to track dependencies async.9 votes ·
Beta Was this translation helpful? Give feedback.
All reactions