Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update
and _Query_ with initial data (#375)
* Add test cases and fix bug * Add one more type test and fix introduced bug * Add missed params * Fix incorrect import * TS ignores * Add more tests and fix bugs about it * Support _Query_ with initial data in `update` operator types * Remove unused import
- Loading branch information
1 parent
102790c
commit e8a1385
Showing
4 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@farfetched/core': patch | ||
--- | ||
|
||
Support _Query_ with initial data in `update` operator types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { type Effect } from 'effector'; | ||
import { expectTypeOf } from 'vitest'; | ||
|
||
import { createMutation } from '../../mutation/create_mutation'; | ||
import { createQuery } from '../../query/create_query'; | ||
import { update } from '../update'; | ||
|
||
describe('update', () => { | ||
test('use null if initial data type is not provided, issue #370', () => { | ||
const queryFx: Effect<void, number[]> = {} as any; | ||
const mutationFx: Effect<number, number> = {} as any; | ||
|
||
const query = createQuery({ | ||
effect: queryFx, | ||
}); | ||
|
||
const mutation = createMutation({ | ||
effect: mutationFx, | ||
}); | ||
|
||
update(query, { | ||
on: mutation, | ||
by: { | ||
success: ({ query }) => { | ||
expectTypeOf(query).toMatchTypeOf< | ||
| { | ||
result: number[]; | ||
params: void; | ||
} | ||
| { | ||
error: Error; | ||
params: void; | ||
} | ||
| null | ||
>(); | ||
|
||
return { | ||
result: [], | ||
}; | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
test('use initial data type in case of not started query, issue #370', () => { | ||
const queryFx: Effect<void, number[]> = {} as any; | ||
const mutationFx: Effect<number, number> = {} as any; | ||
|
||
const query = createQuery({ | ||
effect: queryFx, | ||
initialData: [], | ||
}); | ||
|
||
const mutation = createMutation({ | ||
effect: mutationFx, | ||
}); | ||
|
||
update(query, { | ||
on: mutation, | ||
by: { | ||
success: ({ query }) => { | ||
expectTypeOf(query).toMatchTypeOf< | ||
| { | ||
result: number[]; | ||
params: void; | ||
} | ||
| { | ||
error: Error; | ||
params: void; | ||
} | ||
| { result: number[] } | ||
>(); | ||
return { | ||
result: [], | ||
}; | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters