Skip to main content

Projection

TypeScript Support

A view model projection object has an associated TypeScript type:

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

A view model projection is an object of the following structure:

const projection = {
// The *Init* function creates the view model's initial state object.
Init: () => initialState,
// An event handler function is associated with an event type.
// It receives the view model's 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 NameDescription
stateThe view model's state that is an object of arbitrary structure.
eventAn event object.
argsArguments attached to the request.
contextAn object that contains functions and data related to the current operation (see the Event Handler Context section.)

An event handler should return a new state object.

Contextā€‹

A view model event handler context is an object with the following fields:

Field NameDescription
jwtThe JSON Web Token attached to the request.
encryptThe user-defined encrypt function.
decryptThe user-defined decrypt function.