Move classes to separate files
Absulit opened this issue · comments
This is for readability and convenience. Also for type safety, meaning being sure that the object has the values that it should, also to use the autocomplete in VSCode; that way I don't have to guess the props or go to the part of the code were it was created to be sure.
I want to move all classes but Point class inside absulit.points.module.js to a separate file.
This also includes create a class for so far objects created on the fly to avoid creating a class at that point such as in the listeners array:
addEventListener(name, callback, structSize) {
// this extra 1 is for the boolean flag in the Event struct
let data = Array(structSize + 1).fill(0);
this.addStorageMap(name, data, 'Event', true);
this._events.set(this._events_ids,
{
id: this._events_ids,
name: name,
callback: callback,
}
);
++this._events_ids;
}
Moved classes to separate files, but in cases like the example above, I decided to not create classes because it creates unwanted complexity, you can understand very well the properties of the object here, but if instead you create a class you have to pass everything as parameter or assign each single property, another option would be to create a .fromObject
method to pass this full object to assign its properties to the instance of this class. This is a bit complex and I'm still wondering if it's worth it.