resetHandlers()
将请求处理程序重置为初始列表。
调用签名
¥Call signature
worker.resetHandlers()
方法可以在没有任何参数的情况下调用。完成后,所有 运行时请求处理程序(通过 worker.use()
前置的)都将被删除。
¥The worker.resetHandlers()
method can be called without any arguments. When done so, all the Runtime request handlers (those prepended via worker.use()
) will be removed.
const worker = setupWorker(http.get('/resource', resolver))
worker.use(http.post('/user', resolver))
worker.resetHandlers()
// The "POST /user" runtime request handler is removed,
// and only the "GET /resource" initial request handler remains.
worker.resetHandlers()
方法还接受作为其参数的可选请求处理程序列表。提供这样的列表时,传递给 setupWorker()
的初始请求处理程序也将被删除,并且给定的请求处理程序列表将充当初始处理程序。
¥The worker.resetHandlers()
method also accepts an optional list of request handlers spread as its arguments. When such a list is provided, the initial request handlers passed to setupWorker()
will also be removed, and the given list of request handlers would act as the initial handlers.
const worker = setupWorker(http.get('/resource', resolver))
worker.use(http.post('/user', resolver))
worker.resetHandlers(http.patch('/book/:bookId', resolver))
// Both the runtime "POST /user" and the initial "GET /resource"
// request handlers are removed, and only the "PATCH /book/:bookId"
// request handler remains.
相关材料
¥Related materials