* Wait for children to load, if any. * Then emit `loaded` event and set `hasLoaded`.
(cb, childFilter)
| 112 | * Then emit `loaded` event and set `hasLoaded`. |
| 113 | */ |
| 114 | load (cb, childFilter) { |
| 115 | var children; |
| 116 | var childrenLoaded; |
| 117 | var self = this; |
| 118 | |
| 119 | if (this.hasLoaded) { return; } |
| 120 | |
| 121 | // Default to waiting for all nodes. |
| 122 | childFilter = childFilter || isANode; |
| 123 | // Wait for children to load (if any), then load. |
| 124 | children = this.getChildren(); |
| 125 | childrenLoaded = children.filter(childFilter).map(function (child) { |
| 126 | return new Promise(function waitForLoaded (resolve, reject) { |
| 127 | if (child.hasLoaded) { return resolve(); } |
| 128 | child.addEventListener('loaded', resolve); |
| 129 | child.addEventListener('error', reject); |
| 130 | }); |
| 131 | }); |
| 132 | |
| 133 | Promise.allSettled(childrenLoaded).then(function emitLoaded (results) { |
| 134 | results.forEach(function checkResultForError (result) { |
| 135 | if (result.status === 'rejected') { |
| 136 | // An "error" event has already been fired by THREE.js loader, |
| 137 | // so we don't need to fire another one. |
| 138 | // A warning explaining the consequences of the error is sufficient. |
| 139 | warn('Rendering scene with errors on node: ', result.reason.target); |
| 140 | } |
| 141 | }); |
| 142 | |
| 143 | self.isLoading = true; |
| 144 | self.setupMutationObserver(); |
| 145 | if (cb) { cb(); } |
| 146 | self.isLoading = false; |
| 147 | self.hasLoaded = true; |
| 148 | // loaded-private is an event analog to loaded that gives A-Frame an opportunity to manage internal |
| 149 | // affairs before the publicly loaded event fires and corresponding handlers executed. |
| 150 | self.emit('loaded-private', undefined, false); |
| 151 | self.emit('loaded', undefined, false); |
| 152 | }); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * With custom elements V1 attributeChangedCallback only fires |
no test coverage detected