Skip to content

Latest commit

 

History

History
41 lines (32 loc) · 1.14 KB

projection.md

File metadata and controls

41 lines (32 loc) · 1.14 KB
id title
projection
Projection

:::info TypeScript Support

An aggregate projection object has an associated TypeScript type:

  • Type Name - AggregateProjection
  • Package - @resolve-js/core

:::

An aggregate projection is an object of the following structure:

const projection = {
  // The *Init* function creates the initial aggregate state object.
  Init: () => initialState,
  // An event handler function is associated with an event type.
  // It receives the aggregate state and an incoming event
  // and returns the updated state.
  [EVENT_TYPE]: (state, event) => {
    ...
    return newState
  }
  [EVENT_TYPE2]: (state, event) => ...
  [EVENT_TYPE3]: (state, event) => ...
  ...
}

An event handler implementation receives the following arguments:

Argument Name Description
state The aggregate state that is an object of arbitrary structure.
event An event object.

An event handler should return a new state object.