Skip to content

global once, other minor changes#4

Merged
stackoverfloweth merged 3 commits intomainfrom
global-once
Mar 23, 2024
Merged

global once, other minor changes#4
stackoverfloweth merged 3 commits intomainfrom
global-once

Conversation

@stackoverfloweth
Copy link
Copy Markdown
Contributor

primary objective: add function overload to once for global event

several other side quests along the way that are totally optional for you to consider

@stackoverfloweth stackoverfloweth self-assigned this Mar 23, 2024
src/main.ts Outdated
throw new Error(`Handler must be given for ${String(event)} event`)
}

const { event, handler } = verifyEventAndHandler(globalHandlerOrEvent, maybeHandler)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like this is more straight forward even if its a little less DRY. That way these methods (which are pretty simple) contain all their own business logic and don't require reading utilities to understand what they do.

const event = globalHandlerOrEvent

if(!isHandler(handler) {
  throw new MissingEventHandlerError(event)
}

on(event, handler)

Copy link
Copy Markdown
Collaborator

@pleek91 pleek91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@stackoverfloweth stackoverfloweth merged commit 9f13ec0 into main Mar 23, 2024
@stackoverfloweth stackoverfloweth deleted the global-once branch March 23, 2024 19:49
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