Skip to content

Commit

Permalink
remove axios, add fetch throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
miledivovic committed Oct 30, 2023
1 parent 82e8097 commit 6fdff98
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"main": "/theme.scss",
"dependencies": {
"axios": "^1.4.0",
"bulma": "^0.9.4",
"bulma-checkradio": "^1.1.1",
"bulma-switch": "^2.0.4",
Expand Down
28 changes: 27 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,38 @@ import Clipboard from 'v-clipboard';
import store from './store/index.js';
import InfiniteLoading from 'vue-infinite-loading';
import VueResource from 'vue-resource';
import DOMPurify from 'dompurify';

import VueObserveVisibility from 'vue-observe-visibility';
import AsyncComputed from 'vue-async-computed';

var VueScrollTo = require('vue-scrollto');

const {fetch: originalFetch} = global;

let PENDING_REQUESTS = 0;
const MAX_REQUESTS_COUNT = 10;
const INTERVAL_MS = 10;

global.fetch = async(...args) => {
let [resource, config] = args;
// request interceptor here
if (PENDING_REQUESTS >= MAX_REQUESTS_COUNT) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(global.fetch(...args));
}, INTERVAL_MS);
});
} else {
PENDING_REQUESTS++;
const response = await originalFetch(resource, config);

PENDING_REQUESTS = Math.max(0, PENDING_REQUESTS - 1);
// response interceptor here
return response;
}
};


require("cassproject");
global.UUID = require('pure-uuid');

Expand Down
28 changes: 0 additions & 28 deletions src/store/modules/editor.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,8 @@
import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios';

Vue.use(Vuex);

// Rate Limit axios requests
const MAX_REQUESTS_COUNT = 10;
const INTERVAL_MS = 10;
let PENDING_REQUESTS = 0;

const limitApi = axios.create({});

limitApi.interceptors.request.use(function(config) {
return new Promise((resolve, reject) => {
let interval = setInterval(() => {
if (PENDING_REQUESTS < MAX_REQUESTS_COUNT) {
PENDING_REQUESTS++;
clearInterval(interval);
resolve(config);
}
}, INTERVAL_MS);
});
});

limitApi.interceptors.response.use(function(response) {
PENDING_REQUESTS = Math.max(0, PENDING_REQUESTS - 1);
return Promise.resolve(response);
}, function(error) {
PENDING_REQUESTS = Math.max(0, PENDING_REQUESTS - 1);
return Promise.reject(error);
});

const state = {
framework: null,
organization: null,
Expand Down

0 comments on commit 6fdff98

Please sign in to comment.