/src/storable.ts
/* Storable

This implements a simple way of selecting a set of properties to be stored (e.g. in a JSON blob)

*/

export default abstract class Storable {
    [index: string]: any
    saveProperties: string[] = []

    store(): object {
        const obj: any = {};

        for (let k of this.saveProperties) {
            if (this[k] instanceof Set) {
                obj[k] = Array.from(this[k]);
            } else {
                obj[k] = this[k];
            }
        }

        return obj;
    }

    load(obj: any) {
        for (let k of this.saveProperties) {
            if (this[k] instanceof Set) {
                this[k] = new Set(obj[k]);
            } else {
                this[k] = obj[k];
            }
        }
    }
}