@megalo/api
Version:
重新封装各个端中的API,由 megalo 统一对外抛出方法名。目前微信小程序端提供的 API 最为丰富,所以 API 名称以微信小程序为准。
28 lines (24 loc) • 467 B
JavaScript
export default class InterceptorManager {
constructor() {
this.handlers = [];
}
use(fulfilled, rejected) {
this.handlers.push({
fulfilled,
rejected,
});
return this.handlers.length - 1;
}
eject(id) {
if (this.handlers[id]) {
this.handlers[id] = null;
}
}
forEach(fn) {
this.handlers.forEach(handler => {
if (handler !== null) {
fn(handler);
}
});
}
}