callbacks are fired in backward order

callbacks are fired in backward order

RoyLingRoyLing Posts: 26Questions: 0Answers: 0
edited December 2012 in General
Hi Allan,

In _fnCallbackFire, it's looping over backwards to fire the registered callbacks, why?
Would you mind to explain your thought on this?

Thanks,
Roy

Replies

  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    Yes - its a legacy thing this. IE6 didn't support unshift, so when DataTables, internally, needed to put something at the start of the callback arrays (mainly the draw callback) I put the element at the end of the array and reverse looped over it. In retrospect that was probably wrong, I should have used splice...

    Slightly concerned that changing it to be a forward loop might break things, which is why that baggage is still with us. I might look at altering it when I update the DataTables events system (which really needs a bit of a clean out - but that will be after 1.10 I think now).

    Regards,
    Allan
  • RoyLingRoyLing Posts: 26Questions: 0Answers: 0
    Thanks, nice to hear that you already had plan to alter this confusing behavior in the future release.
    Before I just supposed that the callbacks should be fired/triggered in the order they are registered, but once I found the behavior was different to my assumption, so I dive into the source code and found this. For now, I have to be very careful about the time point to register a callback which may depend on other registered ones. Or I just reminded myself that the callbacks registered have to be independent to avoid the potential problem...

    Regards,
    Roy
  • RoyLingRoyLing Posts: 26Questions: 0Answers: 0
    Allan,

    These days I am looking at jQuery.Callbacks (http://api.jquery.com/category/callbacks-object/) and jQuery.Deferred (http://api.jquery.com/category/deferred-object/) . Do you ever consider to make use of the APIs to enhance the callbacks in DataTables?

    Regards,
    Roy
  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    Possibly yes. DataTables has needed compatibility with 1.4+ previously, but I might increase that to even 1.7 with 1.10 release - not yet sure. I'll certainly be looking into it.

    Allan
This discussion has been closed.