ngokevin / mp3-Suite

Library of wrapper scripts for youtube-dl with Reddit and Rapidshare interfaces
2 stars 0 forks source link

[CLOSED] Require Aframe first, so that THREE.js is available to component. #6

Closed ngokevin closed 8 years ago

ngokevin commented 8 years ago

Issue by donmccurdy Wednesday Dec 30, 2015 at 04:07 GMT Originally opened as https://github.com/ngokevin/aframe-component-boilerplate/pull/6


I tried to define some static THREE.Vector3 instances in index.js, during its initial load. Leaving aside for a moment that it was probably a bad idea, I was confused by the "THREE is not defined" error. Should I have added THREE.js as a <script src="..."></script> tag in my HTML file? Did I need THREE.js as an NPM dependency? If I do that, won't THREE.js be bundled with my dist/* files, and loaded twice for users already including Aframe?

The problem was that main.js loads my component before loading Aframe, and window.THREE is only defined after Aframe loads. I'd like to think there's a better way of doing this, but in case other users make the same mistake it might be safest to load Aframe first.


donmccurdy included the following code: https://github.com/ngokevin/aframe-component-boilerplate/pull/6/commits

ngokevin commented 8 years ago

Comment by donmccurdy Wednesday Dec 30, 2015 at 04:50 GMT


Oh, wait is this so that the user's code will appear first in the compiled output? That kind of makes sense, too. Hoping there's a better way of requiring THREE.js from a component, but if not maybe it's better to close this PR.

ngokevin commented 8 years ago

Comment by ngokevin Wednesday Dec 30, 2015 at 18:25 GMT


A-Frame should always be loaded first. That will set window.THREE for components to use.

In the browser builds, there is a warning if the user requires the component before A-Frame.

Is there anything else that can improve the process?

ngokevin commented 8 years ago

Comment by donmccurdy Thursday Dec 31, 2015 at 01:15 GMT


Sorry yeah, I haven't seen any issues with the dist/* builds. My only concern was that examples/main.js requires index.js before aframe-core, so if you tried to do something like this, you'd get an error in the example demo:

/**
 * index.js
 */

// Constants
var UP = THREE.Vector3(0, 1, 0); // Error: THREE is not defined.

// Component
module.exports.component = {
  schema: { },
  init: function () { },

  // ...
};
ngokevin commented 8 years ago

Comment by donmccurdy Saturday Jan 09, 2016 at 02:09 GMT


Not a big deal, now that i've tried a few more examples. Probably fine to close this.

ngokevin commented 8 years ago

Comment by ngokevin Saturday Jan 09, 2016 at 02:13 GMT


Oops, I didn't see this closely since I was out. I wonder if I had mistaken this for an issue.

The idea of this pull request seems fine. Can you reopen?