aframevr / aframe

:a: Web framework for building virtual reality experiences.
https://aframe.io/
MIT License
16.61k stars 3.94k forks source link

Eliminate single-property schemas. #4009

Open ngokevin opened 5 years ago

ngokevin commented 5 years ago

Description:

Supporting both single and multi prop schemas have made it so most A-Frame internal-related codepaths (and stuff like Inspector, aframe-react) need to branch and check to support both, often causing bugs.

Also causes API breakages when a component decides to go from single to multi prop.

We can eliminate single-prop schemas.

To support components such as visible or perhaps position, we can perhaps have components specify a designated "default property". Where if only a plain value is passed into setAttribute (e.g., true), it will set the designated property.

registerComponent('visible', { 
  schema: {
    visible: {default: true, primary: true}
  }
});

// setAttribute('visible', true);
// equivalent to setAttribute('visible', 'visible', true);
registerComponent('position', { 
  schema: {
    position: {type: 'vec3', primary: true}
  }
});
// setAttribute('position', '0 0 1');
// equivalent to setAttribute('visible', 'position', '0 0 1');
// or we can split to X / Y / Z...
dsinni commented 5 years ago

FWIW, I definitely support keeping single property, even if it does require the extra step in schema setup.

ngokevin commented 5 years ago

It's not just an extra step in the schema setup. It became an additional case to handle throughout all of our tools and through the whole core component codebase. You can keep the API effectively the same while ripping out the internals.