Skip to content

Commit

Permalink
undo changes to cssStyleApplier
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanVukovic99 committed Feb 3, 2024
1 parent c3b594d commit 986a417
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions ext/js/dom/sandbox/css-style-applier.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {fetchJson} from '../../core/fetch-utilities.js';
import {readResponseJson} from '../../core/json.js';

/**
* This class is used to apply CSS styles to elements using a consistent method
Expand Down Expand Up @@ -48,7 +48,7 @@ export class CssStyleApplier {
/** @type {import('css-style-applier').RawStyleData} */
let rawData = [];
try {
rawData = await fetchJson(this._styleDataUrl);
rawData = await this._fetchJsonAsset(this._styleDataUrl);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
Expand Down Expand Up @@ -98,6 +98,28 @@ export class CssStyleApplier {

// Private

/**
* Fetches and parses a JSON file.
* @template [T=unknown]
* @param {string} url The URL to the file.
* @returns {Promise<T>} A JSON object.
* @throws {Error} An error is thrown if the fetch fails.
*/
async _fetchJsonAsset(url) {
const response = await fetch(url, {
method: 'GET',
mode: 'no-cors',
cache: 'default',
credentials: 'omit',
redirect: 'follow',
referrerPolicy: 'no-referrer'
});
if (!response.ok) {
throw new Error(`Failed to fetch ${url}: ${response.status}`);
}
return await readResponseJson(response);
}

/**
* Gets an array of candidate CSS rules which might match a specific class.
* @param {string} className A whitespace-separated list of classes.
Expand Down

0 comments on commit 986a417

Please sign in to comment.