(ampdoc, hostWin, filterFn)
| 151 | * @return {!Promise<!Array<!./service/resource.Resource>>} |
| 152 | */ |
| 153 | export function getMeasuredResources(ampdoc, hostWin, filterFn) { |
| 154 | // First, wait for the `ready-scan` signal. Waiting for each element |
| 155 | // individually is too expensive and `ready-scan` will cover most of |
| 156 | // the initially parsed elements. |
| 157 | return ampdoc |
| 158 | .signals() |
| 159 | .whenSignal(READY_SCAN_SIGNAL) |
| 160 | .then(() => { |
| 161 | // Second, wait for any left-over elements to complete measuring. |
| 162 | const measurePromiseArray = []; |
| 163 | const resources = Services.resourcesForDoc(ampdoc); |
| 164 | resources.get().forEach((r) => { |
| 165 | if (!r.hasBeenMeasured() && r.hostWin == hostWin && !r.hasOwner()) { |
| 166 | measurePromiseArray.push(r.ensureMeasured()); |
| 167 | } |
| 168 | }); |
| 169 | return Promise.all(measurePromiseArray); |
| 170 | }) |
| 171 | .then(() => { |
| 172 | const resources = Services.resourcesForDoc(ampdoc); |
| 173 | return resources.get().filter((r) => { |
| 174 | return ( |
| 175 | r.hostWin == hostWin && |
| 176 | !r.hasOwner() && |
| 177 | r.hasBeenMeasured() && |
| 178 | filterFn(r) |
| 179 | ); |
| 180 | }); |
| 181 | }); |
| 182 | } |
no test coverage detected