In the current version of Booster, reducers and projections receive the previous state as an optional parameter, forcing developers to add additional code to handle a case that, in theory should be impossible:
@Reduces(ProductDeleted)
public static reduceProductDeleted(
event: ProductDeleted,
current?: DocumentEntity
): DocumentEntity {
if (!current) {
return DocumentEntity.DUMMY // Empty object created just to have something to return
}
...
}
Possible Solution
Add a new mandatory method to the entity interface or a decorator instructing Booster on how to build a valid initial state. Entities in Booster are created when the first event is reduced, generally an <EntityName>Created event, but not all events can be used to build the initial state.
Feature Request
Description
In the current version of Booster, reducers and projections receive the previous state as an optional parameter, forcing developers to add additional code to handle a case that, in theory should be impossible:
Possible Solution
Add a new mandatory method to the entity interface or a decorator instructing Booster on how to build a valid initial state. Entities in Booster are created when the first event is reduced, generally an
<EntityName>Created
event, but not all events can be used to build the initial state.