## Proposed solution
- Proposed implementation is much more simpler and can be found here: #272
- Much simpler and cleaner API
- `event` function creates an `io-ts` compatible codec for decoding and creating I/O events
- Expose an additional `event.create` function for building the event
- One place for defining both event schema and creator
- Event type can also be inferred from `matchEvent` operator
Usage:
```typescript
import { event } from '@marblejs/core';
const FooEvent = event('FOO')(t.type({
bar: t.string,
baz: t.boolean,
}));
const fooEvent = FooEvent.create({
bar: 'bar',
baz: false,
});
Problem statement
createEvent
function is a handy event constructor which unfortunately comes with its own limitations and drawbacks.By passing an variadic number of arguments the implementation allows to create non-unary event creators
While calling the constructor, parameters names are not preserved.
Inferred type definition is a bit messy
In order to parse (validate) the I/O event you have to create a separate schema (eg. io-ts schema type) which has to be in sync with an event creator.
The implementation is dirty 🤮
// 1 arg, 1 maybe export function createEvent<T extends string, Payload, Arg1>( type: T, creator: (arg1?: Arg1) => Payload, ): { type: T } & ((arg1?: Arg1) => { type: T; payload: Payload; metadata?: EventMetadata }); // 1 arg export function createEvent<T extends string, Payload, Arg1>( type: T, creator: (arg1: Arg1) => Payload, ): { type: T } & ((arg1: Arg1) => { type: T; payload: Payload; metadata?: EventMetadata });
...
Things to consider
Migration steps
event
I/O decoder won't take place ofcreateEvent
function - their purposes are differentmatchEvent
operator has to be adapted to support new event creator interface - done in #272