|
262 | 262 | * @since v8.0.0 |
263 | 263 | */ |
264 | 264 | /// WillApplyChangesCallback |
265 | | -/** |
266 | | - * The DidSetRowCallback type describes a function called after a Row is changed |
267 | | - * during a transaction, and after mutator listeners have fired. |
268 | | - * |
269 | | - * Unlike the `willSet*` callbacks, which intercept writes as they happen, |
270 | | - * `didSetRow` fires once per touched Row after all cell writes in the |
271 | | - * transaction have completed. This means multiple cell changes to the same Row |
272 | | - * within a single transaction result in just one `didSetRow` call, with the |
273 | | - * full before-transaction and after-transaction Row states. |
274 | | - * |
275 | | - * The callback receives the Table Id, Row Id, the Row as it was at the start of |
276 | | - * the transaction (`oldRow`), and the Row as it is now (`newRow`). It must |
277 | | - * return a Row: |
278 | | - * |
279 | | - * - `newRow` to accept the changes. |
280 | | - * - a different `Row` to replace the final state. |
281 | | - * - `oldRow` to revert all changes to the Row. |
282 | | - * - an empty object to delete the Row. |
283 | | - * |
284 | | - * Multiple DidSetRowCallback functions can be registered for the same table and |
285 | | - * they will be called sequentially, each receiving the Row returned by the |
286 | | - * previous callback. The chain never short-circuits: all registered callbacks |
287 | | - * always run. |
288 | | - * |
289 | | - * Note that `addDidSetRowCallback` is table-scoped: you must specify the table |
290 | | - * Id when registering. Callbacks are only invoked for rows in the specified |
291 | | - * table, keeping overhead to zero for other tables. |
292 | | - * @param tableId The Id of the Table containing the changed Row. |
293 | | - * @param rowId The Id of the Row that was changed. |
294 | | - * @param oldRow The Row as it was at the start of the transaction. |
295 | | - * @param newRow The Row as it is now, after all cell writes including those |
296 | | - * made by mutating listeners. |
297 | | - * @returns The Row to use as the final state. |
298 | | - * @category Callback |
299 | | - * @since v8.0.0 |
300 | | - */ |
301 | | -/// DidSetRowCallback |
302 | 265 | /** |
303 | 266 | * A Middleware object lets you intercept and validate writes to a Store. |
304 | 267 | * |
|
975 | 938 | * @since v8.0.0 |
976 | 939 | */ |
977 | 940 | /// Middleware.addWillApplyChangesCallback |
978 | | - /** |
979 | | - * The addDidSetRowCallback method registers a DidSetRowCallback for a |
980 | | - * specific table that will be called after any Row in that table is changed |
981 | | - * during a transaction, after mutator listeners have fired. |
982 | | - * |
983 | | - * Unlike `willSetRow`, which fires synchronously during each write, this |
984 | | - * callback fires once per changed Row after all cell writes in the |
985 | | - * transaction have landed. Multiple cell changes to the same Row within a |
986 | | - * transaction produce a single callback with the full before/after Row |
987 | | - * states. |
988 | | - * |
989 | | - * The callback receives `oldRow` (the Row at the start of the transaction) |
990 | | - * and `newRow` (the Row after all writes). Return `newRow` to accept, a |
991 | | - * different `Row` to replace, `oldRow` to revert, or an empty object to |
992 | | - * delete. |
993 | | - * @param tableId The Id of the Table to watch. |
994 | | - * @param callback The DidSetRowCallback to register. |
995 | | - * @returns A reference to the Middleware object, for chaining. |
996 | | - * @example |
997 | | - * This example registers a callback that validates the 'pets' table, |
998 | | - * reverting any row that ends up without a required 'species' cell. |
999 | | - * |
1000 | | - * ```js |
1001 | | - * import {createMiddleware, createStore} from 'tinybase'; |
1002 | | - * |
1003 | | - * const store = createStore(); |
1004 | | - * const middleware = createMiddleware(store); |
1005 | | - * |
1006 | | - * middleware.addDidSetRowCallback( |
1007 | | - * 'pets', |
1008 | | - * (_tableId, _rowId, oldRow, newRow) => |
1009 | | - * 'species' in newRow ? newRow : oldRow, |
1010 | | - * ); |
1011 | | - * |
1012 | | - * store.setRow('pets', 'fido', {species: 'dog', name: 'Fido'}); |
1013 | | - * console.log(store.getRow('pets', 'fido')); |
1014 | | - * // -> {species: 'dog', name: 'Fido'} |
1015 | | - * |
1016 | | - * store.setRow('pets', 'nemo', {name: 'Nemo'}); |
1017 | | - * console.log(store.getRow('pets', 'nemo')); |
1018 | | - * // -> {} |
1019 | | - * |
1020 | | - * middleware.destroy(); |
1021 | | - * ``` |
1022 | | - * @example |
1023 | | - * This example shows that multiple cell changes in one transaction result in |
1024 | | - * a single didSetRow callback with the full before/after row states. |
1025 | | - * |
1026 | | - * ```js |
1027 | | - * import {createMiddleware, createStore} from 'tinybase'; |
1028 | | - * |
1029 | | - * const store = createStore(); |
1030 | | - * const middleware = createMiddleware(store); |
1031 | | - * |
1032 | | - * const seen = []; |
1033 | | - * middleware.addDidSetRowCallback( |
1034 | | - * 'pets', |
1035 | | - * (_tableId, rowId, oldRow, newRow) => { |
1036 | | - * seen.push({rowId, oldRow: {...oldRow}, newRow: {...newRow}}); |
1037 | | - * return newRow; |
1038 | | - * }, |
1039 | | - * ); |
1040 | | - * |
1041 | | - * store.transaction(() => { |
1042 | | - * store.setCell('pets', 'fido', 'name', 'Fido'); |
1043 | | - * store.setCell('pets', 'fido', 'species', 'dog'); |
1044 | | - * }); |
1045 | | - * console.log(seen.length); |
1046 | | - * // -> 1 |
1047 | | - * console.log(seen[0].rowId); |
1048 | | - * // -> 'fido' |
1049 | | - * console.log(seen[0].newRow); |
1050 | | - * // -> {name: 'Fido', species: 'dog'} |
1051 | | - * |
1052 | | - * middleware.destroy(); |
1053 | | - * ``` |
1054 | | - * @category Configuration |
1055 | | - * @since v8.0.0 |
1056 | | - */ |
1057 | | - /// Middleware.addDidSetRowCallback |
1058 | 941 | /** |
1059 | 942 | * The destroy method should be called when this Middleware object is no |
1060 | 943 | * longer used. It removes all hooks and listeners from the Store, and |
|
0 commit comments