Skip to content

Commit

Permalink
refactor: use parameter properties where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
x-oflisback committed Sep 18, 2023
1 parent 46f2894 commit a612753
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 114 deletions.
30 changes: 15 additions & 15 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ class Api {
resolve(
result.data.data.items.map(
(workspace: WorkspaceProtocol) =>
new Workspace({
api: this,
definition: workspace.definition,
id: workspace.id,
})
new Workspace(
this,
workspace.definition,
workspace.id
)
)
)
)
Expand Down Expand Up @@ -386,11 +386,11 @@ class Api {
)
.then((response) =>
resolve(
new Workspace({
api: this,
definition: response.data.definition,
id: response.data.id,
})
new Workspace(
this,
response.data.definition,
response.data.id
)
)
)
.catch((e) => reject(toApiError(e)))
Expand Down Expand Up @@ -561,11 +561,11 @@ class Api {
resolve(
result.data.data.items.map(
(project: LocalProjectProtocol) =>
new Project({
api: this,
id: project.id,
workspaceId,
})
new Project(
this,
project.id,
workspaceId
)
)
)
)
Expand Down
37 changes: 8 additions & 29 deletions src/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,14 @@ import Api from './api'
import ModelExecutable from './model-executable'

class Case {
private api: Api
private experimentId: ExperimentId
private fmuId?: FmuId
id: CaseId
runInfo: CaseRunInfo
private workspaceId: WorkspaceId

constructor({
api,
experimentId,
fmuId,
id,
runInfo,
workspaceId,
}: {
api: Api
id: CaseId
fmuId?: FmuId
experimentId: ExperimentId
runInfo: CaseRunInfo
workspaceId: WorkspaceId
}) {
this.api = api
this.fmuId = fmuId
this.id = id
this.runInfo = runInfo
this.experimentId = experimentId
this.workspaceId = workspaceId
}
constructor(
private api: Api,
public id: CaseId,
private experimentId: ExperimentId,
public runInfo: CaseRunInfo,
private workspaceId: WorkspaceId,
private fmuId?: FmuId
) {}

getInput = () =>
this.api.getCaseInput({
Expand Down
6 changes: 1 addition & 5 deletions src/execution-status.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { ExecutionStatusType } from './types'

class ExecutionStatus {
status: ExecutionStatusType

constructor(status: ExecutionStatusType) {
this.status = status
}
constructor(public status: ExecutionStatusType) {}

getNbrCompilationDone = () =>
this.status?.progresses?.filter(
Expand Down
16 changes: 8 additions & 8 deletions src/experiment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class Experiment {

return casesResponse.map(
(caseResponse, i) =>
new Case({
api: this.api,
experimentId: this.id,
fmuId: caseResponse.input.fmu_id,
id: caseResponse.id || i.toString(),
runInfo: caseResponse.run_info,
workspaceId: this.workspaceId,
})
new Case(
this.api,
caseResponse.id || i.toString(),
this.id,
caseResponse.run_info,
this.workspaceId,
caseResponse.input.fmu_id
)
)
}

Expand Down
6 changes: 1 addition & 5 deletions src/model-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ type ModelDescriptionData = {
}

class ModelDescription {
private data: ModelDescriptionData

constructor(data: ModelDescriptionData) {
this.data = data
}
constructor(private data: ModelDescriptionData) {}

getDefaultExperiment() {
const defaultExperiment = this.data.DefaultExperiment
Expand Down
27 changes: 9 additions & 18 deletions src/model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { CustomFunctionOptions, ModelDefinition } from './types'

class Model {
customFunctionOptions?: CustomFunctionOptions
private model: ModelDefinition

private static DefaultModelicaModelContent = {
compilerLogLevel: 'warning',
compilerOptions: {
Expand All @@ -15,16 +12,10 @@ class Model {
runtimeOptions: {},
}

private constructor({
customFunctionOptions,
model,
}: {
customFunctionOptions?: CustomFunctionOptions
model: ModelDefinition
}) {
this.customFunctionOptions = customFunctionOptions
this.model = model
}
private constructor(
private model: ModelDefinition,
public customFunctionOptions?: CustomFunctionOptions
) {}

static from({
className,
Expand All @@ -33,14 +24,14 @@ class Model {
className: string
customFunctionOptions?: CustomFunctionOptions
}) {
return new Model({
customFunctionOptions,
model: { modelica: { className } } as ModelDefinition,
})
return new Model(
{ modelica: { className } } as ModelDefinition,
customFunctionOptions
)
}

static fromModelDefinition(model: ModelDefinition) {
return new Model({ model })
return new Model(model)
}

toModelDefinition() {
Expand Down
22 changes: 5 additions & 17 deletions src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@ import Experiment from './experiment'
import ExperimentDefinition from './experiment-definition'

class Project {
private api: Api
id: ProjectId
private workspaceId: WorkspaceId

constructor({
api,
id,
workspaceId,
}: {
api: Api
id: ProjectId
workspaceId: WorkspaceId
}) {
this.api = api
this.id = id
this.workspaceId = workspaceId
}
constructor(
private api: Api,
public id: ProjectId,
private workspaceId: WorkspaceId
) {}

getExperiments = async () => {
const experimentItems = await this.api.getProjectExperiments({
Expand Down
22 changes: 5 additions & 17 deletions src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,11 @@ import ModelExecutable from './model-executable'
import Project from './project'

class Workspace {
private api: Api
id: WorkspaceId
definition: WorkspaceDefinition

constructor({
api,
definition,
id,
}: {
api: Api
definition: WorkspaceDefinition
id: WorkspaceId
}) {
this.api = api
this.definition = definition
this.id = id
}
constructor(
private api: Api,
public definition: WorkspaceDefinition,
public id: WorkspaceId
) {}

private createExperiment = async (
experimentDefinition: ExperimentDefinition
Expand Down

0 comments on commit a612753

Please sign in to comment.