avocado-old/packages/behavior/item/routines.js

54 lines
1005 B
JavaScript
Raw Normal View History

2019-03-17 23:45:48 -05:00
import {Routine} from './routine';
export class Routines {
constructor() {
2019-04-08 17:42:14 -05:00
this._context = undefined;
2019-03-17 23:45:48 -05:00
this.routines = {};
}
2019-04-08 17:42:14 -05:00
*[Symbol.iterator]() {
for (const index in this.routines) {
const routine = this.routines[index];
yield routine;
}
}
set context(context) {
this._context = context;
for (const routine of this) {
routine.context = context;
}
}
2019-04-25 00:48:53 -05:00
clone(other) {
for (const i in other.routines) {
const routine = other.routines[i];
this.routines[i] = routine.clone();
}
}
2019-03-17 23:45:48 -05:00
fromJSON(json) {
for (const i in json.routines) {
2019-04-25 00:48:53 -05:00
const routineJSON = json.routines[i];
this.routines[i] = (new Routine()).fromJSON(routineJSON);
2019-03-17 23:45:48 -05:00
}
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,
};
}
}