katowulf / mockfirebase

Firebase mock library for writing unit tests (experimental)
157 stars 40 forks source link

Run events scheduled during a flush #69

Closed Grety closed 9 years ago

Grety commented 9 years ago

Transactions work like a charm, however require double .flush() call and do not work for child nodes. (you need a direct reference to the item for transaction). jsfiddle code I guess there is nothing to do about it since on transaction there is a deferred item placed in queue. But this is not evident. And it forced me to debug the MockFirebase to understand that it can work. Should I propose a 1. Tutorial transaction.md? or 2. is there another way to handle transactions with MockFirebase?

bendrucker commented 9 years ago

This is not related to transactions. It has to do with how the flush queue is designed. When you created deferred operations (writes or reads) from within another deferred operation, the brand new operation is not flushed in the same run. You need to flush again. If I'm misinterpreting the issue please elaborate on what's unexpected.

Grety commented 9 years ago

The fact that you have a flush queue is not evident. Those who use your product are not the authors and have no clue about its internals... I will prepare a tutorial and ask you to add a link to it on the the main page among basics, errors and overrides

bendrucker commented 9 years ago

I'll happily take a PR that clarifies the functionality of the flush queue

bendrucker commented 9 years ago

Actually I'd like to think about changing this behavior first.

Angular doesn't actively prevent the deferred queue from adding events that will fire in the same tick: http://plnkr.co/edit/frod0TEi1mLI3GKr3uHq?p=preview

@katowulf Any particular reason why it needs to be the way it is now?

katowulf commented 9 years ago

I can't think of any reason that nested deferreds should have to wait for another flush. It seems that, should a case come up where nested events should not flush, we could probably work around this with the new queue methods we added in recent updates that allow manually canceling or running items in the queue (to have granular control of ordering).