Skip to content

Commit

Permalink
chore: return default flavor if entity cannot be found
Browse files Browse the repository at this point in the history
  • Loading branch information
azech-hqs committed Nov 9, 2022
1 parent a49dc48 commit 3b6f5b4
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/executable.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { mix } from "mixwith";
import { NamedDefaultableInMemoryEntity, RuntimeItemsMixin } from "@exabyte-io/code.js/dist/entity";
import { mix } from "mixwith";

import { Flavor } from "./flavor";

export class Executable extends mix(NamedDefaultableInMemoryEntity).with(RuntimeItemsMixin) {
static Flavor = Flavor;

constructor(config) {
super(config);
}

toJSON(exclude) {
return super.toJSON(["flavors"].concat(exclude));
}
Expand All @@ -18,18 +15,18 @@ export class Executable extends mix(NamedDefaultableInMemoryEntity).with(Runtime
}

get flavors() {
return Object.keys(this.flavorsTree).map(key => {
return this.constructor.Flavor.create(
Object.assign({}, this.flavorsTree[key], {name: key, executable: this})
);
return Object.keys(this.flavorsTree).map((key) => {
return this.constructor.Flavor.create({
...this.flavorsTree[key],
name: key,
executable: this,
});
});
}

get flavorsFromTree() {
return Object.keys(this.flavorsTree).map(key => {
return new this.constructor.Flavor(
Object.assign({}, this.flavorsTree[key], {name: key})
);
return Object.keys(this.flavorsTree).map((key) => {
return new this.constructor.Flavor({ ...this.flavorsTree[key], name: key });
});
}

Expand All @@ -38,11 +35,15 @@ export class Executable extends mix(NamedDefaultableInMemoryEntity).with(Runtime
}

getFlavorByName(name) {
return this.getEntityByName(this.flavors, "flavor", name);
let flavor = this.getEntityByName(this.flavors, "flavor", name);
if (!flavor) {
console.warn(`Could not find flavor '${name}'! Using default instead.`);
flavor = this.defaultFlavor;
}
return flavor;
}

getFlavorByConfig(config) {
return config ? this.getFlavorByName(config.name) : this.defaultFlavor;
}

}

0 comments on commit 3b6f5b4

Please sign in to comment.