File tree Expand file tree Collapse file tree 4 files changed +40
-8
lines changed Expand file tree Collapse file tree 4 files changed +40
-8
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @electric-sql/pglite-vue ' : patch
3
+ ---
4
+
5
+ Fix Vue useLiveQuery to allow no parameters to be provided
Original file line number Diff line number Diff line change @@ -44,10 +44,10 @@ function useLiveQueryImpl<T = { [key: string]: unknown }>(
44
44
45
45
const querySource = typeof query === 'string' ? ref ( query ) : query
46
46
const paramsSources = ! params
47
- ? [ ref ( params ) ]
47
+ ? [ ]
48
48
: Array . isArray ( params )
49
49
? params . map ( ref )
50
- : [ params ]
50
+ : [ ref ( params ) ]
51
51
52
52
const keySource = typeof key === 'string' ? ref ( key ) : key
53
53
@@ -68,13 +68,11 @@ function useLiveQueryImpl<T = { [key: string]: unknown }>(
68
68
69
69
const query = isRef ( querySource ) ? unref ( querySource ) : querySource ( )
70
70
71
- const paramVals = isRef ( params )
72
- ? unref ( params )
71
+ const paramVals = Array . isArray ( params )
72
+ ? params . map ( ( p ) => ( typeof p === 'function' ? p ( ) : unref ( p ) ) )
73
73
: typeof params === 'function'
74
74
? params ( )
75
- : Array . isArray ( params )
76
- ? params . map ( unref )
77
- : [ params ]
75
+ : unref ( params )
78
76
79
77
const key = isRef ( keySource ) ? keySource . value : keySource ?.( )
80
78
Original file line number Diff line number Diff line change @@ -43,6 +43,35 @@ describe('hooks', () => {
43
43
` )
44
44
} )
45
45
46
+ it ( 'updates when query without parameters is provided' , async ( ) => {
47
+ const { useLiveQuery } = await import ( '../src' )
48
+ await db . exec ( `INSERT INTO test (name) VALUES ('test1');` )
49
+
50
+ const result = useLiveQuery ( 'SELECT * FROM test;' )
51
+
52
+ await flushPromises ( )
53
+ expect ( result ?. rows ?. value ) . toEqual ( [
54
+ {
55
+ id : 1 ,
56
+ name : 'test1' ,
57
+ } ,
58
+ ] )
59
+
60
+ await db . exec ( `INSERT INTO test (name) VALUES ('test2');` )
61
+
62
+ await flushPromises ( )
63
+ expect ( result ?. rows ?. value ) . toEqual ( [
64
+ {
65
+ id : 1 ,
66
+ name : 'test1' ,
67
+ } ,
68
+ {
69
+ id : 2 ,
70
+ name : 'test2' ,
71
+ } ,
72
+ ] )
73
+ } )
74
+
46
75
it ( 'updates when query parameter ref changes' , async ( ) => {
47
76
const { useLiveQuery } = await import ( '../src' )
48
77
await db . exec ( `INSERT INTO test (name) VALUES ('test1'),('test2');` )
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ export default defineConfig({
5
5
// @ts -ignore type mismsatch but works?
6
6
plugins : [ vue ( ) ] ,
7
7
test : {
8
- name : 'pglite-react ' ,
8
+ name : 'pglite-vue ' ,
9
9
dir : './test' ,
10
10
watch : false ,
11
11
environment : 'jsdom' ,
You can’t perform that action at this time.
0 commit comments