Skip to content

Commit

Permalink
Remove entity constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
khaosdoctor committed Jan 20, 2019
1 parent 4b7cea0 commit 66c9987
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/classes/EventEntity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IEvent, Reducer, ICommitFunction } from '@nxcd/tardis'
import { IEventEntity } from '../interfaces/IEventEntity'
import { IEntityConstructor } from '../interfaces/IEntityConstructor';

export abstract class EventEntity<TEntity> implements IEventEntity {
[key: string]: any
Expand All @@ -9,28 +8,17 @@ export abstract class EventEntity<TEntity> implements IEventEntity {
id: any = null

protected reducer: Reducer<TEntity>
protected _Entity?: IEntityConstructor<TEntity>

constructor (knownEvents: { [eventName: string]: ICommitFunction<TEntity, any> }, entity?: IEntityConstructor<TEntity>) {
constructor (knownEvents: { [eventName: string]: ICommitFunction<TEntity, any> }) {
this.reducer = new Reducer<TEntity>(knownEvents)

// TODO: Remove this on next major version
if (!entity) {
console.warn("[@nxcd/paradox] DEPRECATED: Calling EventEntity's constructor without passing the Entity constructor is deprecated and will stop being supported soon")
return
}

this._Entity = entity
}

get state (): any {
throw new Error('Method not implemented.')
}

private updateState () {
const state = this._Entity
? this.reducer.reduce(new this._Entity(), [ ...this.persistedEvents, ...this.pendingEvents ])
: this.state
const state = this.state

for (const propertyName of Object.keys(state)) {
this[propertyName] = state[propertyName]
Expand Down

0 comments on commit 66c9987

Please sign in to comment.