2017-01-06 20:49:37 +01:00
|
|
|
import { Enum } from 'enumify';
|
|
|
|
|
2017-01-07 11:38:06 +01:00
|
|
|
import NoOpTransformation from './transformations/NoOpTransformation.jsx';
|
2017-01-07 13:20:04 +01:00
|
|
|
import RoundCoordinatesTransformation from './transformations/RoundCoordinatesTransformation.jsx';
|
|
|
|
import CombineSameYTransformation from './transformations/CombineSameYTransformation.jsx';
|
2017-01-07 11:38:06 +01:00
|
|
|
|
2017-01-06 20:49:37 +01:00
|
|
|
// Holds the state of the Application
|
|
|
|
export default class AppState {
|
|
|
|
|
|
|
|
constructor(options) {
|
|
|
|
this.renderFunction = options.renderFunction;
|
|
|
|
this.mainView = View.UPLOAD;
|
2017-01-09 20:08:32 +01:00
|
|
|
this.fileBuffer;
|
2017-01-06 20:49:37 +01:00
|
|
|
this.pdfPages = [];
|
2017-01-07 13:20:04 +01:00
|
|
|
this.transformations = [new NoOpTransformation(), new RoundCoordinatesTransformation(), new CombineSameYTransformation()];
|
2017-01-06 20:49:37 +01:00
|
|
|
|
|
|
|
//bind functions
|
|
|
|
this.render = this.render.bind(this);
|
2017-01-09 20:08:32 +01:00
|
|
|
this.storeFileBuffer = this.storeFileBuffer.bind(this);
|
|
|
|
this.storePdfPages = this.storePdfPages.bind(this);
|
2017-01-06 20:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
this.renderFunction(this)
|
|
|
|
}
|
|
|
|
|
2017-01-09 20:08:32 +01:00
|
|
|
// the uploaded pdf as file buffer
|
|
|
|
storeFileBuffer(fileBuffer:ArrayBuffer) {
|
|
|
|
this.fileBuffer = fileBuffer;
|
2017-01-06 20:49:37 +01:00
|
|
|
this.mainView = View.LOADING;
|
|
|
|
this.render()
|
|
|
|
}
|
|
|
|
|
2017-01-09 20:08:32 +01:00
|
|
|
storePdfPages(pdfPages) {
|
|
|
|
this.pdfPages = pdfPages;
|
|
|
|
this.fileBuffer = null;
|
|
|
|
this.mainView = View.PDF_VIEW;
|
|
|
|
this.render();
|
2017-01-06 20:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export class View extends Enum {
|
|
|
|
}
|
|
|
|
View.initEnum(['UPLOAD', 'LOADING', 'PDF_VIEW'])
|