|
3 | 3 | This is a reverse chronological list of the major TinyBase releases, with |
4 | 4 | highlighted features. |
5 | 5 |
|
| 6 | +## v3.2 |
| 7 | + |
| 8 | +This release lets you add a listener to the start of a transaction. This lets |
| 9 | +you detect that a set of changes are about to be made to a Store. |
| 10 | + |
| 11 | +To use this, call the addStartTransaction method on your Store. The listener you |
| 12 | +add can itself mutate the data in the Store. |
| 13 | + |
| 14 | +From this release onwards, listeners added with the existing |
| 15 | +addWillFinishTransaction are also able to mutate data. Transactions added with |
| 16 | +the existing addDidFinishTransaction _cannot_ mutate data. |
| 17 | + |
| 18 | +```js |
| 19 | +const store = createStore(); |
| 20 | + |
| 21 | +const startListenerId = store.addStartTransactionListener(() => { |
| 22 | + console.log('Start transaction'); |
| 23 | + console.log(store.getTables()); |
| 24 | + // Can mutate data |
| 25 | +}); |
| 26 | + |
| 27 | +const willFinishListenerId = store.addWillFinishTransactionListener(() => { |
| 28 | + console.log('Will finish transaction'); |
| 29 | + console.log(store.getTables()); |
| 30 | + // Can mutate data |
| 31 | +}); |
| 32 | + |
| 33 | +const didFinishListenerId = store.addDidFinishTransactionListener(() => { |
| 34 | + console.log('Did finish transaction'); |
| 35 | + console.log(store.getTables()); |
| 36 | + // Cannot mutate data |
| 37 | +}); |
| 38 | + |
| 39 | +store.setTable('pets', {fido: {species: 'dog'}}); |
| 40 | +// -> 'Start transaction' |
| 41 | +// -> {} |
| 42 | +// -> 'Will finish transaction' |
| 43 | +// -> {pets: {fido: {species: 'dog'}}} |
| 44 | +// -> 'Did finish transaction' |
| 45 | +// -> {pets: {fido: {species: 'dog'}}} |
| 46 | + |
| 47 | +store |
| 48 | + .delListener(startListenerId) |
| 49 | + .delListener(willFinishListenerId) |
| 50 | + .delListener(didFinishListenerId); |
| 51 | + |
| 52 | +store.delTables(); |
| 53 | +``` |
| 54 | + |
| 55 | +This release also fixes a bug where using the explicit startTransaction method |
| 56 | +_inside_ another listener could create infinite recursion. |
| 57 | + |
6 | 58 | ## v3.1 |
7 | 59 |
|
8 | 60 | This new release adds a powerful schema-based type system to TinyBase. |
@@ -55,7 +107,7 @@ existing tabular data, it allows you to get, set, and listen to, individual |
55 | 107 | Value items, each with a unique Id. |
56 | 108 |
|
57 | 109 | ```js |
58 | | -const store = createStore().setValues({employees: 3, open: true}); |
| 110 | +store.setValues({employees: 3, open: true}); |
59 | 111 | console.log(store.getValues()); |
60 | 112 | // -> {employees: 3, open: true} |
61 | 113 |
|
|
0 commit comments