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

Why does it reset to the first handler when the array is empty? #2410

Open
1 task
nayounsang opened this issue Jan 11, 2025 · 0 comments
Open
1 task

Why does it reset to the first handler when the array is empty? #2410

nayounsang opened this issue Jan 11, 2025 · 0 comments
Labels

Comments

@nayounsang
Copy link

nayounsang commented Jan 11, 2025

Scope

Adds a new behavior

Compatibility

  • This is a breaking change

Feature description

I understand initializing when the argument is undefined, but I think initializing it even when it is an empty array is excessive.
It seems troublesome for developers to classify each case.
If the argument is dynamic, it may lead to unexpected behavior.
(However, it seems difficult to distinguish this technically. Is there a good way?)

const enableMyHandlers = (handlers) => {
  // hmm... handlers.length could be 0. In this case, I don't think there should be any handlers active.
  worker.resetHandlers(...handlers) 
}

const initHandlers = () => {
  // Unlike the above function, this is to obtain the first handler.
  worker.resetHandlers()
}
  public reset(nextHandlers: Array<RequestHandler | WebSocketHandler>): void {
    this.handlers =
      nextHandlers.length > 0 ? [...nextHandlers] : [...this.initialHandlers]
  }

// ...

  public resetHandlers(
    ...nextHandlers: Array<RequestHandler | WebSocketHandler>
  ): void {
    this.handlersController.reset(nextHandlers)
  }

If I can clear the handler, it may be a bit inconvenient, but I think it can be done anyway.
Well, first, let’s create a PR this way. If it's strange, let's discuss another method!

if (someCondition) {
  worker.clearHandlers();
}

// HandlerController
// ...
  public clearHandlers(): void {
    this.handlers = []
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant