Skip to content

Commit

Permalink
chore: with mixins +2
Browse files Browse the repository at this point in the history
  • Loading branch information
seankwarren committed Feb 8, 2024
1 parent fb388a3 commit 777600e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
24 changes: 12 additions & 12 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function ApplicationMixin<
name: string,
version?: string,
build?: string
}): Application {
}) {
return this.createFromNameVersionBuild(config);
}

Expand All @@ -54,30 +54,30 @@ export function ApplicationMixin<
name: string,
version?: string,
build?: string
}): Application {
}) {
return new Application({ name, version, build });
}

getExecutables() {
return this.executables;
}

getBuilds(): string[] {
getBuilds() {
const data = getAppData(this.prop("name")) as ApplicationData;
const { versions } = data;
const builds = ["Default"];
versions.map((v) => v.build && builds.push(v.build));
return lodash.uniq(builds);
}

getVersions(): string[] {
getVersions() {
const data = getAppData(this.prop("name")) as ApplicationData;
const { versions } = data;
const these: string[] = versions.map((v) => v.version);
return lodash.uniq(these);
}

static getUniqueAvailableNames(): string[] {
static getUniqueAvailableNames() {
return allApplications;
}

Expand All @@ -104,19 +104,19 @@ export function ApplicationMixin<
return [];
}

get summary(): string {
get summary() {
return this.prop<string>("summary");
}

get version(): string {
get version() {
return this.prop<string>("version");
}

get build(): string {
get build() {
return this.prop<string>("build");
}

get shortName(): string {
get shortName() {
return this.prop<string>("shortName", this.prop<string>("name"));
}

Expand All @@ -135,15 +135,15 @@ export function ApplicationMixin<
});
}

get hasAdvancedComputeOptions(): boolean {
get hasAdvancedComputeOptions() {
return this.prop<boolean>("hasAdvancedComputeOptions", false);
}

get isLicensed(): boolean {
get isLicensed() {
return this.prop<boolean>("isLicensed", false);
}

get isUsingMaterial(): boolean {
get isUsingMaterial() {
const materialUsingApplications = ["vasp", "nwchem", "espresso", "exabyteml"];
return materialUsingApplications.includes(this.name);
}
Expand Down
13 changes: 8 additions & 5 deletions src/flavor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
RuntimeItemsMixin,
} from "@exabyte-io/code.js/dist/entity";

import { Template } from "./template";
import { Template as AdeTemplate } from "./template";
import { NamedTemplate } from "./types";
import { Constructor } from "@exabyte-io/code.js/dist/context";
import { AnyObject } from "@exabyte-io/code.js/dist/entity/in_memory";
Expand All @@ -12,17 +12,20 @@ const Base = RuntimeItemsMixin(NamedDefaultableHashedInMemoryEntity);
type FlavorBaseEntity = InstanceType<typeof Base>;

export function FlavorMixin<
S extends AdeTemplate = AdeTemplate,
T extends Constructor<FlavorBaseEntity> = Constructor<FlavorBaseEntity>,
>(superclass: T) {
>(superclass: T, Template: S) {
return class Flavor extends superclass {
static Template = Template;

get input(): NamedTemplate[] {
return this.prop<NamedTemplate[]>("input", []);
}

get inputAsTemplates(): Template[] {
get inputAsTemplates() {
return this.input.map((input) => {
const templateName = 'name' in input ? input.name : input.templateName;
const template = Template.fromFlavor(
const template = Flavor.Template.fromFlavor(
this.prop("applicationName"),
this.prop("executableName"),
templateName,
Expand All @@ -44,6 +47,6 @@ export function FlavorMixin<
}
}

export const Flavor = FlavorMixin(Base);
export const Flavor = FlavorMixin(Base, AdeTemplate);

export type Flavor = typeof Flavor;
2 changes: 1 addition & 1 deletion src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ export function TemplateMixin<

export const Template = TemplateMixin(Base);

export type Template = InstanceType<typeof Template>;
export type Template = typeof Template;

0 comments on commit 777600e

Please sign in to comment.