Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Transactions work in the manner of Amazon's SimpleDB or a sharded cluster of databases. That is to say, they are "eventually consistent" rather than guaranteed consistent.</p> <p>So when you are using transactions, the processing function may get called more than once with a local value (in some cases null if it's never been retrieved) and then again with the synced value (whatever is on the server).</p> <p>Example:</p> <pre><code>pathRef.transaction(function(curValue) { // this part is eventually consistent and may be called several times }, function(error, committed, ss) { // this part is guaranteed consistent and will match the final value set }); </code></pre> <p>This is really the mindset with which you must approach transaction anyways. You should always expect multiple calls, since the first transaction may collide with another change and be rejected. You can't use a transaction's processing method to fetch the server value (although you could read it out of the success callback).</p> <p><strong>Preventing the locally triggered event</strong></p> <p>When the transaction happens, a local event is triggered before it reaches the server for latency compensation. If the transaction fails, then the local event will be reverted (a change or remove event is triggered).</p> <p>You can use the <code>applyLocally</code> property <a href="https://www.firebase.com/docs/javascript/firebase/transaction.html" rel="noreferrer">on transactions</a> to override this behavior, which makes the local results slower but ensures that only the server value is triggered locally.</p> <pre><code>pathRef.transaction(function(curValue) { // this is still called multiple times }, function(error, committed, ss) { // this part is guaranteed consistent and will match the final value set }, // by providing a third argument of `true`, no local event // is generated with the locally cached value. true); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload