Skip to content

suggest to make 'createEvents' type friendley - #955

Open
Yuddomack wants to merge 2 commits into
remix-run:devfrom
Yuddomack:dev
Open

suggest to make 'createEvents' type friendley #955
Yuddomack wants to merge 2 commits into
remix-run:devfrom
Yuddomack:dev

Conversation

@Yuddomack

Copy link
Copy Markdown

I was trying to create a custom event for experiment (like this #949)
but did some mistakes because the type was not clear little.

I didn't want to someother make same mistake,
Help them see for themselves what they are doing.

so I added a type specification to help with type inference.

It make improve type inference

before (any) after (inferred)
image image
image image

+ Additionally

multiple parameter passing is possible by this

call(...arg) {
  handlers.forEach((fn) => fn && fn(...arg));
}
before after
image image

if you don't think need multi parameter, can change like this

  • EventType
type Events<F extends EventHandler> = {
  length: number;
  push: (fn: F) => () => void;
  call: (arg: Parameters<F>[0]) => void; // can change optional if need
};
  • Events.call
// ...
call(arg) {
  handlers.forEach((fn) => fn && fn(arg));
},
// ...

Thank you

Please consider to this pull request!
and Thank you for providing a good ecosystem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants