joseph / Monocle

A silky, tactile browser-based ebook JavaScript library.
http://monocle.inventivelabs.com.au
MIT License
743 stars 200 forks source link

More consistent behavior of 'monocle:loaded' #57

Open aronwoost opened 12 years ago

aronwoost commented 12 years ago

This is somehow related to this ticket.

As I need to hook up with the components content (a.k.a. iFrame.contentDocument) directly, the 'monocle:loaded' event has special importants to me. I expect the event to tell me "all components displayed and rendered complete".

However I noticed that this doesn't work reliable. Sometimes pageDiv.m.activeFrame.m.component.properties.pageLength is still undefined when the event is fired.

Also another 'monocle:componentchange'is fired sometimes before and sometimes after 'monocle:loaded'.

In my perfect world 'monocle:loaded' would be fired when both components (in case of using slider) are initialized, measured and rendered. After that I would subscribe to 'monocle:componentchange' and can respond to user interactions.

joseph commented 12 years ago

That sounds like how things work in the ios5-unstable branch. Want to check it?

aronwoost commented 12 years ago

Ah, ok. Yes, will do.

aronwoost commented 12 years ago

First let me say thanks for implementing the "componentchange" changes. Indeed, the components is rendered and measured when "componentchange" is fired:

    function _onComponentChange(evt) {
        console.log(evt.m.component.lastPageNumber()); // cool!
    }

However, the "monocle:loaded" behavior remains unchanged compared to the master branch.

I have either this order: loaded 01 or that: loaded 02 In the first scenario both components are rendered on "monocle:loaded", in the later only one (which makes sense fron the logs, I guess). Also I can confirm, that this is not cache related.

joseph commented 12 years ago

This is quite odd, since the callback that fires loaded is only invoked when we hear two componentchange events (see Reader#setBook). I'll set up a test to try to reproduce it.

aronwoost commented 12 years ago

Let me know if I can provide you with something.

joseph commented 12 years ago

My commit presumptuously closed this. :)

I haven't been able to reproduce it. In my test (test/events/index.html) in the ios5-unstable branch, monocle:loaded always fired after all initial monocle:componentchange events. But I tweaked it so that it would fire even later — after the monocle:turn event when all iframes have moved to the correct page.

Can you check whether this addresses the problem?