MCPcopy
hub / github.com/aframevr/aframe / load

Method load

src/core/a-node.js:114–153  ·  view source on GitHub ↗

* Wait for children to load, if any. * Then emit `loaded` event and set `hasLoaded`.

(cb, childFilter)

Source from the content-addressed store, hash-verified

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

Callers 15

sound.jsFile · 0.45
hand-controls.jsFile · 0.45
loadTextureFunction · 0.45
gltf-model.jsFile · 0.45
obj-model.jsFile · 0.45
ar-hit-test.jsFile · 0.45
doLoadImageUrlFunction · 0.45
camera.jsFile · 0.45
doConnectedCallbackMethod · 0.45
camera.test.jsFile · 0.45
a-entity.test.jsFile · 0.45
a-node.test.jsFile · 0.45

Calls 3

getChildrenMethod · 0.95
setupMutationObserverMethod · 0.80
emitMethod · 0.80

Tested by

no test coverage detected