import * as uuid from 'uuid' ; import { ProjectUpdatePayload } from '@meetalva/message' ; import { EditHistoryCommit } from './edit-history-commit' ; import { revert } from './revert' ; export class EditHistoryStage { public readonly id = uuid . v4 ( ) ; public changes : ProjectUpdatePayload [ ] = [ ] ; public constructor ( changes ? ) { if ( changes ) { this . changes = changes ; } } public get length ( ) { return this . changes . length ; } public add ( change ) { this . changes . push ( change ) ; } public toCommit ( ) { return new EditHistoryCommit ( { id : this . id , changes : this . changes , reverted : false } ) ; } public revert ( ) { return new EditHistoryStage ( this . changes . map ( revert ) ) ; } }