<commit_before>// For conditions of distribution and use, see copyright notice in LICENSE

var componentTypeNames = {};
var componentTypeIds = {};
var componentFactories = {};

function Component(typeId) {
    this.parentEntity = null;
    this.typeId = typeId;
    this.name = "";
    this.id = 0;
    this.supportsDynamicAttributes = false;
    this.attributes = [];
    this.attributeChanged = new signals.Signal();
    this.attributeAdded = new signals.Signal();
    this.attributeRemoved = new signals.Signal();
}

Component.prototype = {
    // Add a new static attribute at initialization
    addAttribute: function(typeId, id, name, value) {
        var newAttr = createAttribute(typeId);
        if (newAttr != null) {
            newAttr.name = name;
            newAttr.id = id;
            newAttr.owner = this;
            if (value != null)
                newAttr.value = value;
            newAttr.index = this.attributes.length;
            this.attributes.push(newAttr);
            // Register direct named access
            var propName = sanitatePropertyName(id);
            if (this[propName] === undefined)
                this[propName] = newAttr;
            return newAttr;
        }
        else
            return null;
    },
    
    // Create a dynamic attribute during runtime
    createAttribute: function(index, typeId, name, value, changeType) {
        if (!this.supportsDynamicAttributes) {
            console.log("Component " + this.typeName + " does not support adding dynamic attributes");
            return null;
        }
        var newAttr = createAttribute(typeId);
        if (newAttr != null) {
            newAttr.name = name;
            newAttr.id = name; // For dynamic attributes name == id
            newAttr.owner = this;
            if (value != null)
                newAttr.value = value;
            newAttr.index = index;
            newAttr.dynamic = true;

            // If needed, make "holes" to the attribute list<commit_msg>change attribute access shorthand in Component to return the value directly, not the Attribute object<commit_after>// For conditions of distribution and use, see copyright notice in LICENSE

var componentTypeNames = {};
var componentTypeIds = {};
var componentFactories = {};

function Component(typeId) {
    this.parentEntity = null;
    this.typeId = typeId;
    this.name = "";
    this.id = 0;
    this.supportsDynamicAttributes = false;
    this.attributes = [];
    this.attributeChanged = new signals.Signal();
    this.attributeAdded = new signals.Signal();
    this.attributeRemoved = new signals.Signal();
}

Component.prototype = {
    // Add a new static attribute at initialization
    addAttribute: function(typeId, id, name, value) {
        var newAttr = createAttribute(typeId);
        if (newAttr != null) {
            newAttr.name = name;
            newAttr.id = id;
            newAttr.owner = this;
            if (value != null)
                newAttr.value = value;
            newAttr.index = this.attributes.length;
            this.attributes.push(newAttr);
            // Register direct named access
            var propName = sanitatePropertyName(id);
            //based on http://stackoverflow.com/questions/1894792/determining-if-a-javascript-object-has-a-given-property
            //instead of hasOwnProperty to not create confusion if someone creates an EC called 'prototype' or so.
            if (!(propName in this)) {
                Object.defineProperty(this, propName, 
                                      {get: function() { return newAttr.value; },
                                       set: function(changedVal) { newAttr.value = changedVal; },
                                       enumerable : true,
                                       configurable : true}); //allows deleting the prop
            }
            return newAttr;
        }
        else
            return null;
    },
    
    // Create a dynamic attribute during runtime
    createAttribute: function(index, typeId, name, value, changeType) {
        if (!this.supportsDynamicAttributes) {
            console.log("Component " + this.typeName + " does not support adding dynamic attributes");
            return null;
        }
        var newAttr = createAttribute(typeId);
        if (newAttr != null) {
            newAttr.name = name;
            newAttr.id = name; // For dynamic attributes name == id
            newAttr.owner = this;
            if (value != null)
                newAttr.value = value;
            newAttr.index = index;
            newAttr.dynamic = true;

            // If needed, make "holes" to the attribute list
{'fraction_non_alphanumeric': 0.09588159588159588, 'fraction_numerical': 0.0019305019305019305, 'mean_word_length': 1.9071072319201996, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3477983', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1151, 'n_words': 343}