Skip to content

Commit c9cec7a

Browse files
committed
[docs] Document onIgnoredError and onSqlCommand
1 parent 42e00ac commit c9cec7a

31 files changed

+103
-9
lines changed

site/guides/3_schemas_and_persistence/4_persisting_data.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,21 @@ You may often want to have both automatic saving and loading of a Store so that
115115
changes are constantly synchronized (allowing basic state preservation between
116116
browser tabs, for example). The framework has some basic provisions to prevent
117117
race conditions - for example it will not attempt to save data if it is
118-
currently loading it and vice-versa.
118+
currently loading it and vice-versa - and will sequentially schedule methods
119+
that could cause race conditions.
119120

120-
Be aware, however, that the default implementations do not provide complex
121-
synchronization heuristics and you should comprehensively test your persistence
121+
That said, be aware that you should always comprehensively test your persistence
122122
strategy to understand the opportunity for data loss (in the case of trying to
123123
save data to a server under poor network conditions, for example).
124124

125+
To help debug such issues, since v4.0.4, the create methods for all Persister
126+
objects take an optional `onIgnoredError` argument. This is a handler for the
127+
errors that the Persister would otherwise ignore when trying to save or load
128+
data (such as when handling corrupted stored data). It's recommended you use
129+
this for debugging persistence issues, but only in a development environment.
130+
Database-based Persister objects also take an optional `onSqlCommand` argument
131+
for logging commands and queries made to the underlying database.
132+
125133
## Summary
126134

127135
Use the persisters module to load and save data from and to a variety of common

src/types/docs/persisters.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,21 @@
565565
* that changes are constantly synchronized (allowing basic state preservation
566566
* between browser tabs, for example). The framework has some basic provisions
567567
* to prevent race conditions - for example it will not attempt to save data if
568-
* it is currently loading it and vice-versa.
568+
* it is currently loading it and vice-versa - and will sequentially schedule
569+
* methods that could cause race conditions.
569570
*
570-
* Be aware, however, that the default implementations do not provide complex
571-
* synchronization heuristics and you should comprehensively test your
571+
* That said, be aware that you should always comprehensively test your
572572
* persistence strategy to understand the opportunity for data loss (in the case
573573
* of trying to save data to a server under poor network conditions, for
574574
* example).
575+
*
576+
* To help debug such issues, since v4.0.4, the create methods for all Persister
577+
* objects take an optional `onIgnoredError` argument. This is a handler for the
578+
* errors that the Persister would otherwise ignore when trying to save or load
579+
* data (such as when handling corrupted stored data). It's recommended you use
580+
* this for debugging persistence issues, but only in a development environment.
581+
* Database-based Persister objects also take an optional `onSqlCommand`
582+
* argument for logging commands and queries made to the underlying database.
575583
* @example
576584
* This example creates a Store, persists it to the browser's session storage as
577585
* a JSON string, changes the persisted data, updates the Store from it, and
@@ -1052,6 +1060,9 @@
10521060
* @param delPersisterListener A function that will unregister the listener from
10531061
* the underlying changes to the persistence layer. It receives whatever was
10541062
* returned from your `addPersisterListener` implementation.
1063+
* @param onIgnoredError An optional handler for the errors that the Persister
1064+
* would otherwise ignore when trying to save or load data. This is suitable for
1065+
* debugging persistence issues in a development environment, since v4.0.4.
10551066
* @returns A reference to the new Persister object.
10561067
* @example
10571068
* This example creates a custom Persister object and persists the Store to a

src/types/docs/persisters/persister-automerge.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
* @param docHandle The Automerge document handler to persist the Store with.
2222
* @param docMapName The name of the map used inside the Automerge document to
2323
* sync the Store to (which otherwise will default to 'tinybase').
24+
* @param onIgnoredError An optional handler for the errors that the Persister
25+
* would otherwise ignore when trying to save or load data. This is suitable for
26+
* debugging persistence issues in a development environment, since v4.0.4.
2427
* @returns A reference to the new Persister object.
2528
* @example
2629
* This example creates a Persister object and persists the Store to an

src/types/docs/persisters/persister-browser.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
* that the browser uses to identify the storage location.
2424
* @param store The Store to persist.
2525
* @param storageName The unique key to identify the storage location.
26+
* @param onIgnoredError An optional handler for the errors that the Persister
27+
* would otherwise ignore when trying to save or load data. This is suitable for
28+
* debugging persistence issues in a development environment, since v4.0.4.
2629
* @returns A reference to the new Persister object.
2730
* @example
2831
* This example creates a Persister object and persists the Store to the
@@ -51,6 +54,9 @@
5154
* that the browser uses to identify the storage location.
5255
* @param store The Store to persist.
5356
* @param storageName The unique key to identify the storage location.
57+
* @param onIgnoredError An optional handler for the errors that the Persister
58+
* would otherwise ignore when trying to save or load data. This is suitable for
59+
* debugging persistence issues in a development environment, since v4.0.4.
5460
* @returns A reference to the new Persister object.
5561
* @example
5662
* This example creates a Persister object and persists the Store to the

src/types/docs/persisters/persister-cr-sqlite-wasm.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
* persist the Store to a local CR-SQLite database (in an appropriate
1313
* environment).
1414
*
15-
* As well as providing a reference to the Store to persist, you must provide
16-
* a `db` parameter which identifies the database instance.
15+
* As well as providing a reference to the Store to persist, you must provide a
16+
* `db` parameter which identifies the database instance.
1717
*
1818
* A database Persister uses one of two modes: either a JSON serialization of
1919
* the whole Store stored in a single row of a table (the default), or a tabular
@@ -31,6 +31,12 @@
3131
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
3232
* persistence mode (or a string to set the `storeTableName` property of the
3333
* JSON serialization).
34+
* @param onSqlCommand An optional handler called every time the Persister
35+
* executes a SQL command or query. This is suitable for logging persistence
36+
* behavior in a development environment, since v4.0.4.
37+
* @param onIgnoredError An optional handler for the errors that the Persister
38+
* would otherwise ignore when trying to save or load data. This is suitable for
39+
* debugging persistence issues in a development environment, since v4.0.4.
3440
* @returns A reference to the new Persister object.
3541
* @example
3642
* This example creates a Persister object and persists the Store to a local

src/types/docs/persisters/persister-expo-sqlite.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
3939
* persistence mode (or a string to set the `storeTableName` property of the
4040
* JSON serialization).
41+
* @param onSqlCommand An optional handler called every time the Persister
42+
* executes a SQL command or query. This is suitable for logging persistence
43+
* behavior in a development environment, since v4.0.4.
44+
* @param onIgnoredError An optional handler for the errors that the Persister
45+
* would otherwise ignore when trying to save or load data. This is suitable for
46+
* debugging persistence issues in a development environment, since v4.0.4.
4147
* @returns A reference to the new Persister object.
4248
* @example
4349
* This example creates a Persister object and persists the Store to a local

src/types/docs/persisters/persister-file.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* `filePath` parameter which identifies the file to persist it to.
1515
* @param store The Store to persist.
1616
* @param filePath The location of the local file to persist the Store to.
17+
* @param onIgnoredError An optional handler for the errors that the Persister
18+
* would otherwise ignore when trying to save or load data. This is suitable for
19+
* debugging persistence issues in a development environment, since v4.0.4.
1720
* @returns A reference to the new Persister object.
1821
* @example
1922
* This example creates a Persister object and persists the Store to a local

src/types/docs/persisters/persister-remote.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
* @param saveUrl The endpoint that supports a `POST` method to save JSON.
2424
* @param autoLoadIntervalSeconds How often to poll the `loadUrl` when
2525
* automatically loading changes from the server.
26+
* @param onIgnoredError An optional handler for the errors that the Persister
27+
* would otherwise ignore when trying to save or load data. This is suitable for
28+
* debugging persistence issues in a development environment, since v4.0.4.
2629
* @returns A reference to the new Persister object.
2730
* @example
2831
* This example creates a Persister object and persists the Store to a remote

src/types/docs/persisters/persister-sqlite-wasm.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
3434
* persistence mode (or a string to set the `storeTableName` property of the
3535
* JSON serialization).
36+
* @param onSqlCommand An optional handler called every time the Persister
37+
* executes a SQL command or query. This is suitable for logging persistence
38+
* behavior in a development environment, since v4.0.4.
39+
* @param onIgnoredError An optional handler for the errors that the Persister
40+
* would otherwise ignore when trying to save or load data. This is suitable for
41+
* debugging persistence issues in a development environment, since v4.0.4.
3642
* @returns A reference to the new Persister object.
3743
* @example
3844
* This example creates a Persister object and persists the Store to a local

src/types/docs/persisters/persister-sqlite3.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
3232
* persistence mode (or a string to set the `storeTableName` property of the
3333
* JSON serialization).
34+
* @param onSqlCommand An optional handler called every time the Persister
35+
* executes a SQL command or query. This is suitable for logging persistence
36+
* behavior in a development environment, since v4.0.4.
37+
* @param onIgnoredError An optional handler for the errors that the Persister
38+
* would otherwise ignore when trying to save or load data. This is suitable for
39+
* debugging persistence issues in a development environment, since v4.0.4.
3440
* @returns A reference to the new Persister object.
3541
* @example
3642
* This example creates a Persister object and persists the Store to a local

0 commit comments

Comments
 (0)