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

[events] Consider events enumeration #6

Closed
kouks opened this issue Dec 11, 2018 · 2 comments
Closed

[events] Consider events enumeration #6

kouks opened this issue Dec 11, 2018 · 2 comments
Labels
enhancement New feature or request

Comments

@kouks
Copy link
Member

kouks commented Dec 11, 2018

Would be nice to standardise all native/framework events under an enumeration instead of using the app.package.event notation.

@kouks kouks changed the title Consider events enumeration [events] Consider events enumeration Dec 11, 2018
@kouks kouks changed the title [events] Consider events enumeration Consider events enumeration #as Dec 11, 2018
@kouks kouks changed the title Consider events enumeration #as [events] Consider events enumeration Dec 14, 2018
@kouks kouks transferred this issue from another repository Dec 22, 2018
@kouks kouks added the enhancement New feature or request label Dec 23, 2018
@porkbrain
Copy link
Contributor

porkbrain commented Jan 3, 2019

I was thinking about this and I suppose moving onwards when having lots of modules that all emit events this is going to be necessary for both IDE hinting of native events, avoiding event overlapping (maybe providers would be responsible for event registering?) and consistency among packages (this is more of our internal issue, not entirely on experanto, but yeah).

Might do for an interesting read:
microsoft/TypeScript#17592

Maybe something like AppEvent.MANAGEMENT.RUNTIME.INSTALLED where MANAGEMENT would be static get of class AppEvent that extends some EventEnum empty interface.

Then in each non-core module you'd register your own implementation:

// PromotionEvent.ts
class PromotionEvent implements EventEnum {
  public static get CLOSED () : string {
    return 'app.promotions.closed'
  }
}

// ModuleProvider.ts
...
register () : void {
  ...
  // Wouldn't put it on dispatcher maybe, just throwing my 5 cents in.
  dispatcher.registerEventTree(new PromotionEvent())
}

and in event registration you could use is like this

import { PromotionEvent } from '...'

// Doing stuff.

dispatcher.fire(PromotionEvent.OPEN)

and registerEventTree (tree: EventEnum) : void would then call all those static methods recursively until it gets all strings such as 'app.promotions.closed', checked that this event is not already in the set of registered events (from another module, ...) and added it there.

This would I guess force developers to think about their event structure and also allowed anyone just to open the file with PromotionEvent to see all events.

This is just a random thing that now came to my mind, it e.g. would have to be changed somewhat to get IDE hinting. But I think it's a step in a right direction and maybe you can think of something better based on this.

@porkbrain
Copy link
Contributor

closed by #43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants