feat: BehaviorItem::clone
This commit is contained in:
parent
080fbb0f34
commit
a5c3b4190e
|
@ -13,7 +13,6 @@ export class Actions extends decorate(Traversals) {
|
|||
constructor() {
|
||||
super();
|
||||
this._index = 0;
|
||||
this.traversals = [];
|
||||
this.pending = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,17 @@ export function Collection(type) {
|
|||
this[plural] = [];
|
||||
}
|
||||
|
||||
clone(other) {
|
||||
if (0 === other[plural].length) {
|
||||
return;
|
||||
}
|
||||
const Item = other[plural][0].constructor;
|
||||
for (let i = 0; i < other[plural].length; ++i) {
|
||||
this[plural][i] = new Item();
|
||||
this[plural][i].clone(other[plural][i]);
|
||||
}
|
||||
}
|
||||
|
||||
count() {
|
||||
return this[plural].length;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,11 @@ export class Condition {
|
|||
return this.get(...args);
|
||||
}
|
||||
|
||||
clone(other) {
|
||||
this.operator = other.operator;
|
||||
this.operands = other.operands.map((operand) => operand.clone());
|
||||
}
|
||||
|
||||
fromJSON(json) {
|
||||
this.operator = json.operator;
|
||||
this.operands = json.operands.map((operand) => {
|
||||
|
|
|
@ -4,6 +4,10 @@ export class Literal {
|
|||
this.value = null;
|
||||
}
|
||||
|
||||
clone(other) {
|
||||
this.value = other.value;
|
||||
}
|
||||
|
||||
fromJSON(json) {
|
||||
this.value = json.value;
|
||||
return this;
|
||||
|
|
|
@ -11,6 +11,10 @@ export class Routine {
|
|||
this._context = context;
|
||||
}
|
||||
|
||||
clone(other) {
|
||||
this.actions = other.actions.clone();
|
||||
}
|
||||
|
||||
fromJSON(json) {
|
||||
this.actions.fromJSON(json.routine);
|
||||
return this;
|
||||
|
|
|
@ -21,9 +21,17 @@ export class Routines {
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
this.routines[i] = (new Routine()).fromJSON(json.routines[i]);
|
||||
const routineJSON = json.routines[i];
|
||||
this.routines[i] = (new Routine()).fromJSON(routineJSON);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,31 @@ export class Traversal {
|
|||
this.value = undefined;
|
||||
}
|
||||
|
||||
clone(other) {
|
||||
this.steps = other.steps.map((step) => {
|
||||
switch (step.type) {
|
||||
case 'key':
|
||||
return step;
|
||||
case 'invoke':
|
||||
return {
|
||||
type: 'invoke',
|
||||
args: step.args.map((arg, index) => {
|
||||
const Item = arg.constructor;
|
||||
const item = new Item();
|
||||
item.clone(arg);
|
||||
return item;
|
||||
}),
|
||||
};
|
||||
}
|
||||
});
|
||||
if (other.value) {
|
||||
this.value = other.value.clone();
|
||||
}
|
||||
if (other.hash) {
|
||||
this.hash = other.hash;
|
||||
}
|
||||
}
|
||||
|
||||
fromJSON(json) {
|
||||
this.steps = json.steps.map((step) => {
|
||||
switch (step.type) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user