chore: simplify entity step filter

This commit is contained in:
cha0s 2019-04-19 23:45:08 -05:00
parent e12cc426ed
commit 69b9f6f090

View File

@ -48,28 +48,28 @@ export class Informed extends decorate(Trait) {
});
}
entityStepFilter(op, invert) {
entityStepFilter(op) {
return (step) => {
if (op !== step.get('op')) {
return invert;
return false;
}
const parts = step.get('parts');
if (!parts) {
return invert;
return false;
}
if (6 !== parts.length) {
return invert;
return false;
}
if ('room' !== parts[1]) {
return invert;
return false;
}
if ('layers' !== parts[2]) {
return invert;
return false;
}
if ('entityList' !== parts[4]) {
return invert;
return false;
}
return !invert;
return true;
};
}
@ -77,7 +77,7 @@ export class Informed extends decorate(Trait) {
steps = steps.map((step) => {
return step.set('parts', step.get('path').split('/'));
});
const isAdd = this.entityStepFilter('add', false);
const isAdd = this.entityStepFilter('add');
const adds = steps.filter(isAdd);
steps = steps.withMutations((steps) => {
const iterator = adds.values();
@ -134,7 +134,7 @@ export class Informed extends decorate(Trait) {
steps = steps.map((step) => {
return step.set('parts', step.get('path').split('/'));
});
const isRemove = this.entityStepFilter('remove', false);
const isRemove = this.entityStepFilter('remove');
const removals = steps.filter(isRemove);
steps = steps.withMutations((steps) => {
for (const removal of removals.values()) {