code-gen refactorings

This commit is contained in:
undergroundwires
2020-01-06 22:22:53 +01:00
parent 60e6348dc8
commit 246e753ddc
7 changed files with 79 additions and 104 deletions

View File

@@ -1,4 +1,4 @@
import { CodeBuilder } from './CodeBuilder';
import { UserScriptGenerator } from './UserScriptGenerator';
import { IUserSelection } from './../Selection/IUserSelection';
import { Signal } from '@/infrastructure/Events/Signal';
import { IApplicationCode } from './IApplicationCode';
@@ -8,12 +8,12 @@ export class ApplicationCode implements IApplicationCode {
public readonly changed = new Signal<string>();
public current: string;
private readonly codeBuilder: CodeBuilder;
private readonly generator: UserScriptGenerator;
constructor(userSelection: IUserSelection, private readonly version: string) {
if (!userSelection) { throw new Error('userSelection is null or undefined'); }
if (!version) { throw new Error('version is null or undefined'); }
this.codeBuilder = new CodeBuilder();
this.generator = new UserScriptGenerator();
this.setCode(userSelection.selectedScripts);
userSelection.changed.on((scripts) => {
this.setCode(scripts);
@@ -21,7 +21,7 @@ export class ApplicationCode implements IApplicationCode {
}
private setCode(scripts: ReadonlyArray<IScript>) {
this.current = this.codeBuilder.buildCode(scripts, this.version);
this.current = scripts.length === 0 ? '' : this.generator.buildCode(scripts, this.version);
this.changed.notify(this.current);
}
}