Skip to content

Commit

Permalink
docs(async): fix params usage
Browse files Browse the repository at this point in the history
  • Loading branch information
artalar committed Apr 10, 2023
1 parent 2442ca3 commit d6f51cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/async/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const fetchList = reatomAsync(
onReject(ctx, error) {
errorAtom(ctx, error)
},
onEffect(ctx, promise, params) {
onEffect(ctx, params, promise) {
// clear outdated data on request start
listAtom(ctx, [])
errorAtom(ctx, null)
Expand Down Expand Up @@ -261,7 +261,7 @@ export const updateList = reatomAsync(
},
{
name: 'updateList',
onEffect(ctx, promise, params) {
onEffect(ctx, params, promise) {
const [newList] = params
const newList = fetchList.dataAtom(ctx, newList)
},
Expand Down
10 changes: 2 additions & 8 deletions packages/async/src/index.story.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ describe('optimistic update', () => {
),
)
const putData = reatomAsync.from(api.putData)
onUpdate(putData, (ctx, promise, { state }) => {
// `state` is a list of calls during transaction
// this callback will be called on each action call
// and `state.at(-1)` will always(!) contain the call data
// here `promise == payload` and `params == [newList]`
const { payload, params } = state.at(-1)!

onUpdate(putData, (ctx, promise, { params }) => {
const [id, value] = params
const oldList = ctx.get(getData.dataAtom)
// optimistic update
Expand All @@ -62,7 +56,7 @@ describe('optimistic update', () => {
// TODO looks like user changed data again
// need to notify user about the conflict.
}
throw error;
throw error
})
})

Expand Down

1 comment on commit d6f51cb

@vercel
Copy link

@vercel vercel bot commented on d6f51cb Apr 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.