Skip to content

Commit

Permalink
Move component variables from instance to prototype (fix #5273)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarcos committed Apr 21, 2023
1 parent 7050d7b commit 2a6acf9
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/core/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ var Component = module.exports.Component = function (el, attrValue, id) {
this.attrName = this.name + (id ? '__' + id : '');
this.evtDetail = {id: this.id, name: this.name};
this.initialized = false;
this.isSingleProperty = isSingleProp(this.schema);
this.isSinglePropertyObject = this.isSingleProperty &&
isObject(parseProperty(undefined, this.schema)) &&
!(this.schema.default instanceof window.HTMLElement);
this.isObjectBased = !this.isSingleProperty || this.isSinglePropertyObject;
this.el.components[this.attrName] = this;
this.objectPool = objectPools[this.name];

Expand Down Expand Up @@ -519,7 +514,6 @@ Component.prototype = {
data = previousData instanceof Object
? copyData(nextData, previousData)
: nextData;

// Apply defaults.
for (key in schema) {
defaultValue = schema[key].default;
Expand Down Expand Up @@ -615,6 +609,7 @@ module.exports.registerComponent = function (name, definition) {
var proto = {};
var schema;
var schemaIsSingleProp;
var isSinglePropertyObject;

// Warning if component is statically registered after the scene.
if (document.currentScript && document.currentScript !== aframeScript) {
Expand Down Expand Up @@ -676,8 +671,12 @@ module.exports.registerComponent = function (name, definition) {

schema = utils.extend(processSchema(NewComponent.prototype.schema,
NewComponent.prototype.name));
schemaIsSingleProp = isSingleProp(NewComponent.prototype.schema);
NewComponent.prototype.isSingleProperty = schemaIsSingleProp = isSingleProp(NewComponent.prototype.schema);
NewComponent.prototype.isSinglePropertyObject = isSinglePropertyObject = schemaIsSingleProp &&
isObject(parseProperty(undefined, schema)) &&
!(schema.default instanceof window.HTMLElement);

NewComponent.prototype.isObjectBased = !schemaIsSingleProp || isSinglePropertyObject;
// Keep track of keys that may potentially change the schema.
if (!schemaIsSingleProp) {
NewComponent.prototype.schemaChangeKeys = [];
Expand All @@ -694,7 +693,9 @@ module.exports.registerComponent = function (name, definition) {
components[name] = {
Component: NewComponent,
dependencies: NewComponent.prototype.dependencies,
isSingleProp: schemaIsSingleProp,
isSingleProperty: NewComponent.prototype.isSingleProperty,
isSinglePropertyObject: NewComponent.prototype.isSinglePropertyObject,
isObjectBased: NewComponent.prototype.isObjectBased,
multiple: NewComponent.prototype.multiple,
name: name,
parse: NewComponent.prototype.parse,
Expand Down

0 comments on commit 2a6acf9

Please sign in to comment.