@nent/core
Version:
56 lines (51 loc) • 1.63 kB
JavaScript
/*!
* NENT 2022
*/
import { M as Mutex } from './mutex-e5645c85.js';
import { c as createStore } from './index-4bfabbbd.js';
var ReferenceType;
(function (ReferenceType) {
ReferenceType["script"] = "script";
ReferenceType["styles"] = "styles";
})(ReferenceType || (ReferenceType = {}));
/* istanbul ignore file */
class StateModel {
}
const store = createStore({
references: [],
cache: {},
});
const { state, onChange, reset, dispose } = store;
const collectionMutex = new Mutex();
/**
* It returns true if the given url is in the list of references
* @param {string} url - The URL of the reference to check for.
* @returns A boolean value.
*/
async function hasReference(url) {
return await collectionMutex.dispatch(async () => {
return state.references.includes(url);
});
}
/**
* It takes a URL, adds it to the list of references, and returns a promise that resolves when the
* operation is complete
* @param {string} url - The URL of the reference to mark.
* @returns A promise that resolves to the result of the function passed to dispatch.
*/
async function markReference(url) {
return await collectionMutex.dispatch(async () => {
state.references = [
...new Set([...state.references, url]),
];
});
}
/**
* It clears the references to the objects in the `references` array.
*/
async function clearReferences() {
return await collectionMutex.dispatch(async () => {
state.references = [];
});
}
export { ReferenceType as R, StateModel as S, state as a, clearReferences as c, dispose as d, hasReference as h, markReference as m, onChange as o, reset as r, store as s };