Skip to content

feat: dispatch custom entity lifecycle events - #330

Open
elpete wants to merge 2 commits into
nextfrom
feat/85-custom-entity-events
Open

feat: dispatch custom entity lifecycle events#330
elpete wants to merge 2 commits into
nextfrom
feat/85-custom-entity-events

Conversation

@elpete

@elpete elpete commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Closes #85

Review

Entity-specific lifecycle interception points are a good fit for Quick. They let interceptors express domain intent directly instead of subscribing to every generic Quick event and branching on entity metadata.

Recommendation: 8/10.

Reasons for

  • Produces smaller, clearer interceptors such as onOrderCreated.
  • Keeps domain event naming next to the entity lifecycle configuration.
  • Supports one or several custom points for a lifecycle event.
  • Reuses the exact Quick lifecycle event data and respects withoutFiringEvents.

Reasons against

  • Entity classes become aware of application interception-point names.
  • Custom points still need to be registered with ColdBox so interceptors can observe them.
  • Synchronous custom handlers add work to entity persistence and can make side effects less obvious.
  • This is event dispatch, not a durable transactional event/outbox mechanism.

Implementation

Entities can define:

variables._dispatchesEvents = {
    "postInsert" : "onOrderCreated",
    "postSave"   : [ "onOrderSaved", "onAggregateChanged" ]
};

fireEvent continues to invoke the entity lifecycle method and announce the standard quick... point first, then announces each configured custom point using the same event data.

Test-first evidence

Before implementation, creating the public test entity produced an empty custom-event list instead of [ "onSongCreated", "onSongSaved", "onMediaSaved" ].

The integration test now registers those custom ColdBox points, creates a normal Quick entity, verifies string and array mappings in lifecycle order, and verifies the dispatched entity data.

Validation

  • Focused custom-event spec: 1 passed, 0 failed, 0 errors
  • Full suite: 496 passed, 0 failed, 0 errors, 3 skipped
  • Formatter completed
  • git diff --check passed
  • Tested with qb@14.0.0-beta.3

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

Successfully merging this pull request may close these issues.

1 participant