init
This commit is contained in:
60
src/models/Env.ts
Normal file
60
src/models/Env.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { EnvParam } from "./EnvParam";
|
||||
import { NamedId } from "./NamedId";
|
||||
|
||||
|
||||
export class Env implements NamedId {
|
||||
constructor(
|
||||
public id?: number,
|
||||
public name?: string,
|
||||
public params: EnvParam[] = []
|
||||
) { }
|
||||
|
||||
public isDefault() {
|
||||
return this.name === "DEFAULT";
|
||||
}
|
||||
|
||||
addParams(payload: EnvParam): Env {
|
||||
payload.id = Math.random() * 10000;
|
||||
this.params.push(payload);
|
||||
return new Env(this.id, this.name, [...this.params]);
|
||||
}
|
||||
|
||||
delParam(param: EnvParam): Env {
|
||||
let idx = this.params.findIndex(el => el.id === param.id);
|
||||
if (idx > -1) {
|
||||
const newP = this.params.filter(el => el.id !== param.id);
|
||||
return new Env(this.id, this.name, newP);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public updateParams(param: EnvParam): Env {
|
||||
let idx = this.params.findIndex(el => el.id === param.id);
|
||||
if (idx > -1) {
|
||||
let newP = [...this.params];
|
||||
newP[idx] = param;
|
||||
return new Env(this.id, this.name, newP);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export class AppEvent<T> {
|
||||
protected constructor(public payload: T) { }
|
||||
|
||||
public static add<T>(payload: T): AppEvent<T> {
|
||||
return new AddEvent(payload);
|
||||
}
|
||||
public static del<T>(payload: T): AppEvent<T> {
|
||||
return new DelEvent(payload);
|
||||
}
|
||||
public static update<T>(payload: T): AppEvent<T> {
|
||||
return new UpdateEvent(payload);
|
||||
}
|
||||
}
|
||||
|
||||
export class AddEvent<T> extends AppEvent<T> { }
|
||||
export class UpdateEvent<T> extends AppEvent<T> { }
|
||||
export class DelEvent<T> extends AppEvent<T> { }
|
||||
Reference in New Issue
Block a user