# Typed events instead of plain Hash?

**URL:** <https://discourse.dry-rb.org/t/typed-events-instead-of-plain-hash/1012>\
**Category:** Ideas\
**Created:** [March 19, 2020, 10:00am UTC](https://discourse.dry-rb.org/t/typed-events-instead-of-plain-hash/1012 "2020-03-19T10:00:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MicMicMon](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/micmicmon/32/495_2.png) [@MicMicMon](https://discourse.dry-rb.org/u/MicMicMon)\
**Post date:** [March 19, 2020, 10:00am UTC](https://discourse.dry-rb.org/t/typed-events-instead-of-plain-hash/1012/1 "2020-03-19T10:00:26Z")

</div>

I am jumping with joy into the dry ecosystem.

I am exploring with `dry-events`, and saw the payload seems to be “just” a Hash.

Is there any idiomatic way to make it a `Dry::Struct` for example, or at least validate the hash when publishing an event?

I’m about to write a small wrapper to do that, but maybe it has already been done/proofed before?

---

<div class="post-metadata">

**Author:** ![MicMicMon](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/micmicmon/32/495_2.png) [@MicMicMon](https://discourse.dry-rb.org/u/MicMicMon)\
**Post date:** [March 21, 2020, 8:32am UTC](https://discourse.dry-rb.org/t/typed-events-instead-of-plain-hash/1012/2 "2020-03-21T08:32:25Z")

</div>

There is this sentence in the docs, but I can’t make sense of it:

> Publishers are created using Dry::Events::Publisher extension, which is created by providing a unique identifier. **An extended class can be used to define the type of events it can publish**

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [March 21, 2020, 11:43am UTC](https://discourse.dry-rb.org/t/typed-events-instead-of-plain-hash/1012/3 "2020-03-21T11:43:51Z")

</div>

> [@MicMicMon](#):
>
> I am jumping with joy into the dry ecosystem.

YAY! Welcome 🙂

> [@MicMicMon](#):
>
> I am exploring with `dry-events` , and saw the payload seems to be “just” a Hash.
> 
> Is there any idiomatic way to make it a `Dry::Struct` for example, or at least validate the hash when publishing an event?

There’s no public API to do that but it is possible. The reason why it’s a plain `Hash` is because performance is a great concern here. Creating plain hashes will be multiple times faster than Structs. We could consider adding an API that would allow you to specify payload constructors (as in, something that would build a payload however _you_ want), but it’s a very, very low priority right now. This is a post-1.0.0 type of a feature.

> [@MicMicMon](#):
>
> There is this sentence in the docs, but I can’t make sense of it:

I hope this will make it more clear:

 ![Screenshot 2020-03-21 at 12.34.57](https://canada1.discourse-cdn.com/flex031/uploads/dry_rb/original/1X/15c837a95154a7d00cdd99b56a8f70e2676c8345.png)

- `include Dry::Events::Publisher[:my_publisher]` returns _a module object_ which is identified by `:my_publisher` symbol, then it gets included in the `Application` class and provides `register_event` class method
- `register_event` defines an event type that you will be able to use with this publisher class
