()
| 29 | } |
| 30 | |
| 31 | record () { |
| 32 | let networkPromises |
| 33 | if (VIEW_LOAD_LOG) { console.group('Recording view:', this.view.id) } |
| 34 | |
| 35 | // Static pages do not measure resource loading |
| 36 | if (this.firstLoad && application.loadedStaticPage && me.isAnonymous()) { |
| 37 | this.skippingNetworkResources = true |
| 38 | networkPromises = [] |
| 39 | } else { |
| 40 | let views = [this.view] |
| 41 | networkPromises = [] |
| 42 | while (views.length) { |
| 43 | const subView = views.pop() |
| 44 | views = views.concat(_.values(subView.subviews)) |
| 45 | if (!subView.supermodel.finished()) { |
| 46 | networkPromises.push(subView.supermodel.finishLoading()) |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | if (VIEW_LOAD_LOG) { console.log('Network promises:', networkPromises.length) } |
| 51 | const thatThereId = this.view.id |
| 52 | return Promise.all(networkPromises) |
| 53 | .then(() => { |
| 54 | let img |
| 55 | this.networkLoad = performance.now() |
| 56 | if (this.view.destroyed) { return } |
| 57 | |
| 58 | const imagePromises = [] |
| 59 | if (VIEW_LOAD_LOG) { |
| 60 | console.groupCollapsed('Images') |
| 61 | console.groupCollapsed('Skipping (not :visible)') |
| 62 | for (img of Array.from(this.view.$('img:not(:visible)'))) { |
| 63 | console.log(img.src) |
| 64 | } |
| 65 | console.groupEnd() |
| 66 | } |
| 67 | for (img of Array.from(this.view.$('img:visible'))) { |
| 68 | if (!img.complete) { |
| 69 | const promise = new Promise(function (resolve) { |
| 70 | if (img.complete) { |
| 71 | return resolve() |
| 72 | } else { |
| 73 | img.onload = resolve |
| 74 | img.onerror = resolve |
| 75 | } |
| 76 | }) |
| 77 | promise.imgSrc = img.src |
| 78 | imagePromises.push(promise) |
| 79 | } |
| 80 | if (VIEW_LOAD_LOG) { console.log(img.src, (img.complete ? '' : '(still loading)')) } |
| 81 | } |
| 82 | |
| 83 | if (VIEW_LOAD_LOG) { console.groupEnd() } |
| 84 | this.imagesAlreadyLoaded = imagePromises.length === 0 |
| 85 | return Promise.all(imagePromises) |
| 86 | }).then(() => { |
| 87 | let networkTime, resourceInfo |
| 88 | let endTime = performance.now() |
no test coverage detected