code-gen refactorings
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user