mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
move validation to get/set
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
a9a5766920
commit
13594b7851
@ -37,13 +37,43 @@ export class Workspace implements WorkspaceModel, WorkspaceState {
|
|||||||
*
|
*
|
||||||
* @observable
|
* @observable
|
||||||
*/
|
*/
|
||||||
@observable id: WorkspaceId;
|
@observable _id: WorkspaceId;
|
||||||
|
|
||||||
|
set id(id: WorkspaceId) {
|
||||||
|
id = id?.trim();
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
throw new Error("Workspace's id must be trimmable none-empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
this._id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get id(): WorkspaceId {
|
||||||
|
return this._id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Workspace name
|
* Workspace name
|
||||||
*
|
*
|
||||||
* @observable
|
* @observable
|
||||||
*/
|
*/
|
||||||
@observable name: string;
|
@observable private _name: string;
|
||||||
|
|
||||||
|
set name(name: string) {
|
||||||
|
name = name?.trim();
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
throw new Error("Workspace's name must be trimmable none-empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
this._name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
get name(): string {
|
||||||
|
return this._name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Workspace description
|
* Workspace description
|
||||||
*
|
*
|
||||||
@ -246,18 +276,14 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
addWorkspace(workspace: Workspace) {
|
addWorkspace(workspace: Workspace): Workspace | false {
|
||||||
const { id, name } = workspace;
|
const { id, name } = workspace;
|
||||||
|
|
||||||
if (!name.trim() || this.getByName(name.trim())) {
|
if (this.getByName(name)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.workspaces.set(id, workspace);
|
this.workspaces.set(id, workspace);
|
||||||
|
|
||||||
if (!workspace.isManaged) {
|
|
||||||
workspace.enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
appEventBus.emit({name: "workspace", action: "add"});
|
appEventBus.emit({name: "workspace", action: "add"});
|
||||||
|
|
||||||
return workspace;
|
return workspace;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user