wolkenkit
Documentation
News
DocumentationReferenceCreating the read modelDefining lists

Defining lists

To define a list, create a .js file with the name of the list within the server/readModel/lists directory:

$ cd <app>
$ touch server/readModel/lists/<list>.js

Shared code

The server/readModel/lists directory must only contain lists. If you want to add a directory or a file that is shared across multiple lists, put it into the server/shared folder.

E.g., if you want to define a list called invoices, use the following directory structure:

<app>
  server
    flows
    readModel
      lists
        invoices.js
    shared
    writeModel

Where is the context?

In contrast to the write model the read model does not use contexts. This is because a read model can handle events from multiple contexts, so it may not be possible to assign a read model to a specific context.

Structuring the code

Every list uses the same base structure. Hence, you can prepare a list by simply copying and pasting the following template:

'use strict';

const fields = {};

const when = {};

module.exports = { fields, when };