avocado-old/packages/behavior/item/routines.js
2019-11-20 01:01:26 -06:00

46 lines
842 B
JavaScript

import {Routine} from './routine';
export class Routines {
constructor() {
this.routines = {};
}
*[Symbol.iterator]() {
for (const index in this.routines) {
const routine = this.routines[index];
yield routine;
}
}
clone(other) {
for (const i in other.routines) {
const routine = other.routines[i];
this.routines[i] = routine.clone();
}
}
fromJSON(json) {
for (const i in json.routines) {
const routineJSON = json.routines[i];
this.routines[i] = (new Routine()).fromJSON(routineJSON);
}
return this;
}
routine(index) {
return this.routines[index];
}
toJSON() {
const routines = {};
for (const i in this.routines) {
routines[i] = this.routines[i].toJSON();
}
return {
type: 'routines',
routines,
};
}
}