58 lines
1.0 KiB
JavaScript
58 lines
1.0 KiB
JavaScript
import {Routine} from './routine';
|
|
|
|
export class Routines {
|
|
|
|
static type() {
|
|
return 'routines';
|
|
}
|
|
|
|
constructor() {
|
|
this._context = undefined;
|
|
this.routines = {};
|
|
}
|
|
|
|
*[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;
|
|
}
|
|
}
|
|
|
|
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,
|
|
};
|
|
}
|
|
}
|