Screenplay all: project across event types
A projection-level all block in Cratis Screenplay subscribes to every event type, including types not named in a from block. Use it to record activity across event types for each event source, the identifier to which an event belongs.
every shares mappings across events the projection already subscribes to. It does not broaden those subscriptions. That difference matters when an event unrelated to your declared from blocks arrives: all handles it, while every alone does not.
Count activity for each event source
Section titled “Count activity for each event source”This projection excerpt counts events and records the latest occurrence time without naming individual event types:
projection EventCounter => EventCounterReadModel all count totalEvents lastOccurred = $eventContext.occurredIf source A has two events and source B has one, their read model instances have totalEvents values of 2 and 1. all widens the event-type subscription; it does not merge event sources into one global total. See projection keys before choosing how to group an aggregate.
Add detail for a named event
Section titled “Add detail for a named event”Combine all with from when you need a shared activity measure and extra information from one event type:
projection ActivityFeed => ActivityFeedModel all count totalSystemEvents lastActivity = $eventContext.occurred
from UserRegistered recentUsers = nameUserRegistered sets recentUsers as well as running the shared mappings. An event type without its own handler still updates the count and timestamp on the instance keyed by its source. Despite the name totalSystemEvents, this example keeps per-source counts. recentUsers holds the latest mapped name, not a collection of users.
When a named handler declares a key, its key selects the affected instance. The event-source default applies to event types without a handler. A join event that matches no instance does not fall back to creating one under its own source. Do not assume that adding all overrides your existing routing.
Difference Between all and every
Section titled “Difference Between all and every”| Choice | all |
every |
|---|---|---|
| Event types | Subscribes to every event type | Uses the projection’s existing subscriptions |
| Shared mappings | Run across event types, including those without a from block |
Run for subscribed events, including child events by default |
| Typical question | When did this source last have any activity? | When did this profile last change? |
In the following profile excerpt, the declared events are registration and email changes. An unrelated event type does not update LastUpdated:
# Uses 'every' — only runs for UserRegistered and UserEmailChangedprojection UserProfile => UserProfileModel every LastUpdated = $eventContext.occurred
from UserRegistered Name = name
from UserEmailChanged Email = emailThe audit projection instead accepts event types it does not name. Each event source gets its own count and timestamp:
# Uses 'all' — runs for every event type in the entire systemprojection SystemAuditLog => AuditLogModel all count totalEvents lastEventAt = $eventContext.occurredKeep the subscription at projection level
Section titled “Keep the subscription at projection level”Use one all or every block at a given level. Inside a child or nested block, all behaves as every and produces a diagnostic; it does not create a system-wide subscription.
The reference evaluator supports all alongside projection-level from and join mappings, but not alongside removals, child collections, or nested objects. Keep those combinations out of a model you intend to evaluate as a specification.
If you only need common fields for the projection’s existing events, continue with every. To count those events, use counters; to sum amounts carried by them, use arithmetic.