Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat(store): provide current project
Browse files Browse the repository at this point in the history
  • Loading branch information
TheReincarnator committed Dec 8, 2017
1 parent aaf999c commit 246b706
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Project } from './project';

export class Store {
@MobX.observable private currentPage?: Page;
@MobX.observable private projects: Project[] = [];
@MobX.observable private projects: Map<string, Project> = new Map();
private patternRoot: PatternFolder;
@MobX.observable private selectedElement?: PageElement;
@MobX.observable private styleGuidePath: string;
Expand All @@ -19,6 +19,10 @@ export class Store {
return this.currentPage;
}

public getCurrentProject(): Project | undefined {
return this.currentPage ? this.getProjectById(this.currentPage.getProjectId()) : undefined;
}

public getPattern(path: string): Pattern | undefined {
return this.patternRoot.getPattern(path);
}
Expand All @@ -31,8 +35,12 @@ export class Store {
return this.patternRoot;
}

public getProjectById(id: string): Project | undefined {
return this.projects.get(id);
}

public getProjects(): Project[] {
return this.projects;
return Array.from(this.projects.values());
}

public getProjectsPath(): string {
Expand All @@ -55,7 +63,7 @@ export class Store {
}
this.styleGuidePath = styleGuidePath;
this.currentPage = undefined;
this.projects = [];
this.projects.clear();
this.patternRoot = new PatternFolder(this, 'patterns');

const projects: Project[] = [];
Expand All @@ -76,7 +84,10 @@ export class Store {

projects.push(new Project(folder.name, folder.name, pages));
});
this.projects = projects;

projects.forEach(project => {
this.projects.set(project.getId(), project);
});
});
}

Expand Down

0 comments on commit 246b706

Please sign in to comment.