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

Commit

Permalink
feat(store): auto-saving page when switching to another page or style…
Browse files Browse the repository at this point in the history
…guide
  • Loading branch information
TheReincarnator committed Dec 18, 2017
1 parent c63db83 commit 1c96caf
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export class Store {
}

public openStyleguide(styleguidePath: string): void {
// TODO: Replace workaround by proper dirty-check handling
this.save();

MobX.transaction(() => {
if (!PathUtils.isAbsolute(styleguidePath)) {
// Currently, store is two levels below alva, so go two up
Expand Down Expand Up @@ -167,6 +170,9 @@ export class Store {
}

public openPage(id: string): void {
// TODO: Replace workaround by proper dirty-check handling
this.save();

MobX.transaction(() => {
const pagePath: string = PathUtils.join(this.getPagesPath(), `page-${id}.yaml`);
const json: JsonObject = Persister.loadYamlOrJson(pagePath);
Expand All @@ -184,12 +190,17 @@ export class Store {
}

public save(): void {
if (this.currentPage) {
if (!this.getStyleGuidePath()) {
return;
}

const currentPage: Page | undefined = this.getCurrentPage();
if (currentPage) {
const pagePath: string = PathUtils.join(
this.getPagesPath(),
`page-${this.currentPage.getId()}.yaml`
`page-${currentPage.getId()}.yaml`
);
Persister.saveYaml(pagePath, this.currentPage.toJsonObject());
Persister.saveYaml(pagePath, currentPage.toJsonObject());
}

const projectsJsonObject: JsonObject = { projects: [] };
Expand Down

0 comments on commit 1c96caf

Please sign in to comment.