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

Remove event type and keyword #717

Closed
Y-Nak opened this issue May 23, 2022 · 4 comments
Closed

Remove event type and keyword #717

Y-Nak opened this issue May 23, 2022 · 4 comments

Comments

@Y-Nak
Copy link
Collaborator

Y-Nak commented May 23, 2022

Currently, we use event type defined with event keyword to emit an event.
But actually, we could handle event types in the same way as types defined with the struct keyword, i.e., normal user-defined struct.
The only difference between event and struct would be topic, so it would be necessary to introduce some special syntax or language features that enable it to be specified.

Currently, I'd like to propose allowing @[indexed] or @[topic] attribute in the field like below.

struct MyEvent:
    @[indexed]
    x: i32

    y: i32

In the short-term plan, we could treat @[indexed] attribute specially, then generalize the attribute feature in the long-term plan.

@Y-Nak Y-Nak changed the title Remove event type from Remove event type May 23, 2022
@Y-Nak Y-Nak changed the title Remove event type Remove event type and keyword May 23, 2022
@distractedm1nd
Copy link

What effect does this have (or would it have in the future) on indexed fields?

@cburgdorf
Copy link
Collaborator

In the short-term plan, we could treat @[indexed] attribute specially, then generalize the attribute feature in the long-term plan.

I agree we should do this. This is basically the only thing holding us back from adding an emit<T: Event>(val: T) {..} message directly on context.fe in the std lib.

@cburgdorf
Copy link
Collaborator

What effect does this have (or would it have in the future) on indexed fields?

I think the main advantages of treating events as structs are:

  1. Less special syntax
  2. Code re-use (e.g. being able to use the a Foo struct for foo things and just happen to also emit it as an event)
  3. Flexibility. If events are just structs, chances are people can come up with nice little helper libraries down the road

@Y-Nak
Copy link
Collaborator Author

Y-Nak commented Sep 28, 2022

#772

@Y-Nak Y-Nak closed this as completed Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants