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
We need a way to handle optimistic UI easily. The idea is accumulate rollback during transaction and do not cleanup them up until async transaction end. To prevent state collision and for first simple version we could lock touched atoms for mutations and throw an error if somebody trying to change an atom during it lock. In this flow we allow the only simple isolated transactions but it will already better than nothing.
Example.
constreatomLike=(post)=>{constlike=reatomAsync((ctx)=>api.toggleLike(ctx,post.id)).pipe(withDataAtom(post.like),withAbort(),asTransaction());onUpdate(like,(ctx)=>like.dataAtom(ctx,(state)=>!state));// THIS will be done automatically by `asTransaction`// onUpdate(like.onReject, (ctx) => like.dataAtom(ctx, (state) => !state));returnlike;};constfetchFeed=reatomAsync((ctx,from)=>api.getFeed(ctx,from)).pipe(withDataAtom([],(ctx,{ data },state)=>[
...state,
...data.map((post)=>({ ...post,like: reatomLike(post)})),]));
This discussion was converted from issue #512 on April 02, 2024 13:20.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We need a way to handle optimistic UI easily. The idea is accumulate rollback during transaction and do not cleanup them up until async transaction end. To prevent state collision and for first simple version we could lock touched atoms for mutations and throw an error if somebody trying to change an atom during it lock. In this flow we allow the only simple isolated transactions but it will already better than nothing.
Example.
Beta Was this translation helpful? Give feedback.
All reactions