eventstore

A simple filebased eventsourced store

< Back to frontpage

modelDefinition

modelDefinition: object


Full (and commented) version:

let modelDefinition = {

	// The snapshotName is optional. If none provided, snapshots are disabled for this model.
	snapshotName: "name-of-the-model",

	initializeLogAggregatorData(){
		return {};
	},

	createLogAggregator(logAggregatorData){
		// This method is used to instantiate the LogAggregator. This will usually be a constructor.
		// The logAggregator must will manipulate the incomming logAggregatorData object.

		let aLogAggregatorInstance = new SomeLogAggregator(logAggregatorData);
		return aLogAggregatorInstance;
	},

	createDomainModel(dispatch, logAggregatorData){
		let aDomainModel = new DomainModel(dispatch, logAggregatorData);
		return aDomainModel;
	},
}

Shorter alternate syntaxes for defining eventHandlers and initializing the required objects:

let modelDefinition = {

	// Optional:
	snapshotName: "name-of-the-model",

	initializeLogAggregatorData: () => ({}),

	createLogAggregator: logAggregatorData => new SomeLogAggregator(logAggregatorData),

	createDomainModel: (dispatch, logAggregatorData) => new DomainModel(dispatch, logAggregatorData),
}