export class AttributeData { public data: T; constructor( private element: Element, private attribute: string, defaultValue: T, ) { let attributeData = element.getAttribute(attribute); if (!attributeData) { console.warn( `Playground/AttributeData: Attribute "${attribute}" is not set - using empty object.`, element, ); this.data = defaultValue; } else { this.data = JSON.parse(attributeData); } } //todo trigger save automatically when touch on data - but not via MobX save() { //console.log('AttributeData.save()',this.element,this.data); this.element.setAttribute(this.attribute, JSON.stringify(this.data)); } }