@nent/core
Version:
66 lines (60 loc) • 1.78 kB
JavaScript
/*!
* NENT 2022
*/
;
const mutex = require('./mutex-7ae5ebad.js');
const index = require('./index-96f3ab3f.js');
exports.ReferenceType = void 0;
(function (ReferenceType) {
ReferenceType["script"] = "script";
ReferenceType["styles"] = "styles";
})(exports.ReferenceType || (exports.ReferenceType = {}));
/* istanbul ignore file */
class StateModel {
}
const store = index.createStore({
references: [],
cache: {},
});
const { state, onChange, reset, dispose } = store;
const collectionMutex = new mutex.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 = [];
});
}
exports.StateModel = StateModel;
exports.clearReferences = clearReferences;
exports.dispose = dispose;
exports.hasReference = hasReference;
exports.markReference = markReference;
exports.onChange = onChange;
exports.reset = reset;
exports.state = state;
exports.store = store;