Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/20221108 #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 16 additions & 15 deletions src/executable.js
@@ -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.getEntityByName(this.flavors, "flavor", undefined); // extracts default flavor
}
return flavor;
}

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

}