You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
</code></pre><h3id="summary">Summary</h3><p>We've covered all of the essential basics of working with a TinyBase <ahref="/api/the-essentials/creating-stores/store/"><code>Store</code></a>, but that's still just the start!</p><p>Before we move on, we have a quick aside about how to use various flavors of TinyBase in your app, in the <ahref="/guides/the-basics/importing-tinybase/">Importing TinyBase</a> guide.</p></section>
89
+
</code></pre><h3id="transaction-lifecycle">Transaction Lifecycle</h3><p>Since TinyBase now has multiple phases around a transaction, it helps to think of one complete transaction in this order:</p><ol><li>The transaction starts.</li><li><code>startTransaction</code> listeners fire (as added with the <ahref="/api/store/interfaces/store/store/methods/listener/addstarttransactionlistener/"><code>addStartTransactionListener</code></a> method).</li><li>Your transaction actions run.</li><li>For each attempted write in those actions, middleware callbacks run first (as added with the addWillSetRow method, for example).</li><li><ahref="/api/store/type-aliases/transaction/changes/"><code>Changes</code></a> are buffered in the transaction log; non-mutating listeners are not called yet.</li><li>Mutating listeners fire for net changes and invalid attempts (as added with the <ahref="/api/the-essentials/listening-for-changes/addrowlistener/"><code>addRowListener</code></a> method, for example, with the final <code>mutator</code> flag set).</li><li>Any writes made by mutating listeners also go through middleware, but do not trigger mutating listeners again.</li><li>If provided to the <ahref="/api/the-essentials/setting-data/transaction/"><code>transaction</code></a> method or the <ahref="/api/store/interfaces/store/store/methods/transaction/starttransaction/"><code>startTransaction</code></a> method, <code>doRollback</code> runs with the transaction log after all mutating listeners and their writes.</li><li>If <code>doRollback</code> returns <code>true</code>, TinyBase rolls back the transaction changes.</li><li><code>willFinish</code> transaction listeners fire (as added with the <ahref="/api/store/interfaces/store/store/methods/listener/addwillfinishtransactionlistener/"><code>addWillFinishTransactionListener</code></a> method).</li><li>Non-mutating listeners fire for the final committed result (if the transaction has not rolled back).</li><li><code>didFinish</code> transaction listeners fire (as added with the <ahref="/api/store/interfaces/store/store/methods/listener/adddidfinishtransactionlistener/"><code>addDidFinishTransactionListener</code></a> method).</li></ol><p>If transactions are nested, this full lifecycle only happens when the outermost transaction finishes.</p><h3id="summary">Summary</h3><p>We've covered all of the essential basics of working with a TinyBase <ahref="/api/the-essentials/creating-stores/store/"><code>Store</code></a>, but that's still just the start!</p><p>Before we move on, we have a quick aside about how to use various flavors of TinyBase in your app, in the <ahref="/guides/the-basics/importing-tinybase/">Importing TinyBase</a> guide.</p></section>
0 commit comments