Skip to content

Commit

Permalink
Merge pull request #383 from freon4dsl/fix-open-model-with-same-nodeid
Browse files Browse the repository at this point in the history
Clear all caches when opening a new model, otherwise nodes with the s…
  • Loading branch information
joswarmer authored Sep 19, 2024
2 parents 73fcdf2 + ba2cb8f commit a110a43
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/core-svelte/src/lib/components/FreonComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
ARROW_LEFT,
DELETE,
ENTER,
ARROW_RIGHT, isNullOrUndefined, isTableRowBox, isElementBox,
} from "@freon4dsl/core";
ARROW_RIGHT, isNullOrUndefined, isTableRowBox, isElementBox
} from "@freon4dsl/core"
import RenderComponent from "./RenderComponent.svelte";
import ContextMenu from "./ContextMenu.svelte";
import { afterUpdate, onMount, tick } from "svelte";
Expand Down Expand Up @@ -161,7 +161,7 @@
const refreshRootBox = (why?: string) => {
rootBox = editor.rootBox;
LOGGER.log("REFRESH " + why + " ==================> FreonComponent with rootbox " + rootBox?.id);
LOGGER.log("REFRESH " + why + " ==================> FreonComponent with rootbox " + rootBox?.id + " unit " + (!!(rootBox?.node) ? rootBox.node["name"] : "undefined"));
};
refreshRootBox("Initialize FreonComponent");
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/editor/FreEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class FreEditor {
}

auto = () => {
// console.log("CALCULATE NEW ROOTBOX rootelement is " + this?.rootElement?.freLanguageConcept());
LOGGER.log("CALCULATE NEW ROOTBOX rootelement is " + this?.rootElement?.freLanguageConcept() + " name " + (!!this.rootElement ? this.rootElement["name"] : "undefined"));
if (this.rootElement !== null) {
this._rootBox = this.projection.getBox(this.rootElement);
this.rootBoxChanged();
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/editor/projections/FreProjectionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ export class FreProjectionHandler {
});
}

/**
* Clears the element provider map, needed whenever a new model is opened
*/
clear(): void {
this.elementToProvider.clear()
}

/////////// The main methods ///////////

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/environment/FreEnvironment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FreEditor } from "../editor";
import { FreEditor, FreProjectionHandler } from "../editor"
import { FreInterpreter } from "../interpreter";
import { FreValidator } from "../validator";
import { FreScoperComposite } from "../scoper";
Expand All @@ -21,6 +21,7 @@ export interface FreEnvironment {
writer: FreWriter;
reader: FreReader;
interpreter: FreInterpreter;
projectionHandler: FreProjectionHandler;

languageName: string;
fileExtensions: Map<string, string>;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/environment/FreLanguageEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class FreLanguageEnvironment implements FreEnvironment {
public validator: FreValidator;
public writer: FreWriter;
public interpreter: FreInterpreter;
public projectionHandler: FreProjectionHandler;

// @ts-ignore
// function needs to be implemented because it is part of the interface FreEnvironment
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/storage/InMemoryModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class InMemoryModel {
* @param name
*/
async createModel(name: string): Promise<FreModel> {
LOGGER.log(`createModel ${name}`)
this.__model = this.languageEnvironment.newModel(name);
await this.server.createModel(name);
this.currentModelChanged();
Expand Down Expand Up @@ -79,6 +80,7 @@ export class InMemoryModel {
* @param unitConcept
*/
async createUnit(name: string, unitConcept: string): Promise<FreModelUnit> {
LOGGER.log(`createUnit ${name} of type ${unitConcept}`)
const newUnit = this.model.newUnit(unitConcept);
newUnit.name = name;
await this.server.createModelUnit(this.model.name, newUnit);
Expand Down Expand Up @@ -110,6 +112,7 @@ export class InMemoryModel {
* @param unit
*/
async addUnit(unit: FreModelUnit): Promise<void> {
LOGGER.log(`addUnit ${unit?.name}`)
this.model.addUnit(unit);
await this.saveUnit(unit);
this.currentModelChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class EnvironmentTemplate {
initializeEditorDef();
initializeScoperDef(this.scoper);
initializeTypers(this.typer);
this.projectionHandler = myComposite;
}
/**
Expand All @@ -84,6 +85,7 @@ export class EnvironmentTemplate {
writer: ${Names.FreWriter} = new ${Names.writer(language)}();
reader: ${Names.FreReader} = new ${Names.reader(language)}();
interpreter: ${Names.FreInterpreter} = new ${Names.interpreterName(language)};
projectionHandler: FreProjectionHandler;
languageName: string = "${language.name}";
fileExtensions: Map<string, string> = new Map([
${language.modelConcept.unitTypes().map((unit) => `["${Names.classifier(unit)}", "${unit.fileExtension}"]`)}
Expand Down
4 changes: 3 additions & 1 deletion packages/webapp-lib/src/lib/language/EditorState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file contains all methods to connect the webapp to the Freon generated language editorEnvironment and to the server that stores the models
import { FreError, FreErrorSeverity, FreLogger, InMemoryModel } from "@freon4dsl/core";
import { BoxFactory, FreError, FreErrorSeverity, FreLogger, InMemoryModel } from "@freon4dsl/core"
import type {
FreEnvironment,
FreNode,
Expand Down Expand Up @@ -104,6 +104,8 @@ export class EditorState {
first = false;
}
}
BoxFactory.clearCaches()
this.langEnv.projectionHandler.clear()
EditorState.getInstance().showUnitAndErrors(this.currentUnit);
} else {
editorProgressShown.set(false);
Expand Down

0 comments on commit a110a43

Please sign in to comment.