Skip to content

Conversation

@ngokevin
Copy link
Member

@ngokevin ngokevin commented Aug 1, 2016

Description:

Entities were not waiting for assets to load This caused duplicate asset fetching if an asset was defined in <a-assets> and an entity was also fetching an asset through a component.

This makes entities wait for <a-assets> (if exists) to load. This ensures all <a-asset-item>s have been fetched and made into the THREE.Cache used by THREE.XHRLoader. Subsequent fetches from loaders (e.g., ColladaLoader, OBJLoader, MTLLoader) will automatically pull from the cache.

Depended on #1689, which has been merged.

Changes proposed:

  • Entity wait for <a-assets> to load if exists.
  • Update asset system documentation.
var src = this.getAttribute('src');
var src;

src = this.getAttribute('src');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can declaration and assignment be in the same line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to do separate declarations, I prefer to keep them pure declarations when we can. If the intent is to separate declaration and logic and make the style 100% unquestionable with no exception, this does that.

I've found mixing declarations and initializations is what requires me to do frequent code restructuring (like in case we added an early return, or we needed assignments to go in a certain order).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in this function for instance do I have to do?

function () {
  var camera;
  var canvas;
  var embedded;
  var size;
  camera = this.camera;
  canvas = this.canvas;
  embedded =  this.getAttribute('embedded') && !this.is('vr-mode');
}

It feels like a lot of clutter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, note that we got tempted to initialize embedded even though it might not even get used if it returns early: https://github.com/aframevr/aframe/blob/master/src/core/scene/a-scene.js#L266

Mixing declaration/logic also messes up the alphabetization sometimes if the variables depend on each other.

I am not sure where to draw the line. Perhaps only allow pure declarations and aliasing (e.g., var el = this.el) in the declaration block. Everything else is logic and goes after.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it. I guess I will just use discretion on when to declare + assign (small functions), and when to declare + assign later (large functions or functions with multiple paths).

@dmarcos dmarcos merged commit 5728902 into aframevr:master Aug 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants