1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Optimize performance by using singletons for items

This commit is contained in:
tobspr
2020-08-14 13:09:10 +02:00
parent 3c34227c24
commit 8c39d31c5b
18 changed files with 145 additions and 88 deletions

View File

@@ -98,3 +98,13 @@ export class ColorItem extends BaseItem {
context.fill();
}
}
/**
* Singleton instances
* @type {Object<enumColors, ColorItem>}
*/
export const COLOR_ITEM_SINGLETONS = {};
for (const color in enumColors) {
COLOR_ITEM_SINGLETONS[color] = new ColorItem(color);
}

View File

@@ -37,7 +37,6 @@ export class ShapeItem extends BaseItem {
*/
constructor(definition) {
super();
// logger.log("New shape item for shape definition", definition.generateId(), "created");
/**
* This property must not be modified on runtime, you have to clone the class in order to change the definition