Skip to content

Commit

Permalink
Refactoring: Suppress nonsense output, Add returns types for ts.
Browse files Browse the repository at this point in the history
`
  • Loading branch information
Pawel Siemienik committed Apr 18, 2020
1 parent 73c58fc commit a40fcee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
23 changes: 10 additions & 13 deletions src/Scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export class Scope {
return this.template.worksheets[this.templateCell.ws].getCell(this.templateCell.r, this.templateCell.c);
}

public setCurrentOutputValue(value: CellValue) {
public setCurrentOutputValue(value: CellValue): void {
if (this.frozen) {
return;
}
this.output.worksheets[this.outputCell.ws].getCell(this.outputCell.r, this.outputCell.c).value = value;
}

public applyStyles() {
public applyStyles(): void {
if (this.frozen) {
return;
}
Expand All @@ -45,7 +45,7 @@ export class Scope {
}
}

public applyMerge() {
public applyMerge(): void {
const tws = this.template.worksheets[this.templateCell.ws];
const tc = tws.getCell(this.templateCell.r, this.templateCell.c);

Expand All @@ -62,15 +62,15 @@ export class Scope {
}
}

public incrementCol() {
public incrementCol(): void {
if (!this.finished) {
this.templateCell = Object.freeze({ ...this.templateCell, c: this.templateCell.c + 1 });
}

this.outputCell = Object.freeze({ ...this.outputCell, c: this.outputCell.c + 1 });
}

public incrementRow() {
public incrementRow(): void {
if (!this.finished) {
this.templateCell = Object.freeze({ ...this.templateCell, r: this.templateCell.r + 1, c: 1 });
}
Expand All @@ -83,27 +83,24 @@ export class Scope {
}
}

public freezeOutput() {
public freezeOutput(): void {
this.frozen++;
}

public unfreezeOutput() {
public unfreezeOutput(): void {
this.frozen = Math.max(this.frozen - 1, 0);
}

/**
* @returns {boolean}
*/
public isFrozen() {
public isFrozen(): boolean {
return this.frozen > 0;
}

public finish() {
public finish(): void {
this.finished = true;
this.unfreezeOutput();
}

public isFinished() {
public isFinished(): boolean {
return this.finished;
}
}
4 changes: 2 additions & 2 deletions src/cell/VariableCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export class VariableCell extends BaseCell {
.split('.') || [];

const value = path.reduce((p, c) => (typeof p === 'object' ? p[c] : p), scope.vm);
if (value === undefined) {
if (value === undefined && !scope.isFrozen()) {
// todo do it better (use logger or somethink like that)
// tslint:disable-next-line:no-console
console.warn(
`WARN: ${path} is undefined for output: ${scope.outputCell} when template is:${scope.templateCell}`,
`WARN: ${path} is undefined for output: ${JSON.stringify(scope.outputCell)} when template is:${JSON.stringify(scope.templateCell)}`,
);
}
scope.setCurrentOutputValue(value);
Expand Down

0 comments on commit a40fcee

Please sign in to comment.