Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support entities without class constructors #5

Open
3 tasks
mpareja opened this issue Jul 30, 2020 · 0 comments
Open
3 tasks

Support entities without class constructors #5

mpareja opened this issue Jul 30, 2020 · 0 comments

Comments

@mpareja
Copy link
Owner

mpareja commented Jul 30, 2020

Gearshaft's EntityStore and PostgresDocumentStore currently require entities to be implemented using classes. Class constructors are the expected value of the entity parameter when creating such stores.

Existing users would be familiar with the following entity store declaration:

createEntityStore({
  category: 'registration',
  entity: Registration,
  projection: RegistrationProjection,
  messageStore
})

The proposed change would instead require users to provide a function to instantiate entities. For class-based entities, the syntax would look as follows:

createEntityStore({
  category: 'registration',
  entity: () => new Registration(),
  projection: RegistrationProjection,
  messageStore
})

Note, the entity parameter now encapsulates how the entities are instantiated.

Reasoning

The proposed change enables more flexible construction of entities and lifts the requirement for all entities to be implemented as classes.

Plan

  • PostgresDocumentStore: update entity parameter usage
  • EntityStoreSubstitute: receives entity parameter usage
  • EntityStore: receives entity parameter usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant