InterceptorManager.js 569 B

1234567891011121314151617181920212223242526272829
  1. import _ from '@/assets/scripts/lodash';
  2. function InterceptorManager() {
  3. this.handlers = [];
  4. }
  5. InterceptorManager.prototype.add = function (resolveFn, rejectFn) {
  6. this.handlers.push({
  7. resolve: resolveFn,
  8. reject: rejectFn
  9. });
  10. return this.handlers.length - 1;
  11. }
  12. InterceptorManager.prototype.remove = function (id) {
  13. if (this.handlers[id]) {
  14. this.handlers[id] = null;
  15. }
  16. }
  17. InterceptorManager.prototype.forEach = function (fn) {
  18. _.forEach(this.handlers, (handler) => {
  19. if (handler !== null) {
  20. fn(handler);
  21. }
  22. });
  23. }
  24. export default InterceptorManager;