@powersync/react 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/WatchedQuery.js +5 -4
- package/lib/hooks/useQuery.js +7 -2
- package/package.json +2 -2
package/lib/WatchedQuery.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseObserver } from '@powersync/common';
|
|
1
|
+
import { BaseObserver, runOnSchemaChange } from '@powersync/common';
|
|
2
2
|
export class Query {
|
|
3
3
|
rawQuery;
|
|
4
4
|
sqlStatement;
|
|
@@ -91,7 +91,7 @@ export class WatchedQuery extends BaseObserver {
|
|
|
91
91
|
const onError = (error) => {
|
|
92
92
|
this.setError(error);
|
|
93
93
|
};
|
|
94
|
-
|
|
94
|
+
const watchQuery = async (abortSignal) => {
|
|
95
95
|
await this.fetchTables();
|
|
96
96
|
await this.fetchData();
|
|
97
97
|
if (!this.options.runQueryOnce) {
|
|
@@ -102,11 +102,12 @@ export class WatchedQuery extends BaseObserver {
|
|
|
102
102
|
onError
|
|
103
103
|
}, {
|
|
104
104
|
...this.options,
|
|
105
|
-
signal:
|
|
105
|
+
signal: abortSignal,
|
|
106
106
|
tables: this.tables
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
|
-
}
|
|
109
|
+
};
|
|
110
|
+
runOnSchemaChange(watchQuery, this.db, { signal: this.controller.signal });
|
|
110
111
|
}
|
|
111
112
|
setData(results) {
|
|
112
113
|
this.isReady = true;
|
package/lib/hooks/useQuery.js
CHANGED
|
@@ -79,10 +79,15 @@ export const useQuery = (query, parameters = [], options = { runQueryOnce: false
|
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
React.useEffect(() => {
|
|
82
|
-
|
|
82
|
+
const updateData = async () => {
|
|
83
83
|
await fetchTables();
|
|
84
84
|
await fetchData();
|
|
85
|
-
}
|
|
85
|
+
};
|
|
86
|
+
updateData();
|
|
87
|
+
const l = powerSync.registerListener({
|
|
88
|
+
schemaChanged: updateData
|
|
89
|
+
});
|
|
90
|
+
return () => l?.();
|
|
86
91
|
}, [powerSync, memoizedParams, sqlStatement]);
|
|
87
92
|
React.useEffect(() => {
|
|
88
93
|
// Abort any previous watches
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/react",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://docs.powersync.com",
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@powersync/common": "^1.
|
|
25
|
+
"@powersync/common": "^1.21.0",
|
|
26
26
|
"react": "*"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|