UNPKG

@nent/core

Version:

Functional elements to add routing, data-binding, dynamic HTML, declarative actions, audio, video, and so much more. Supercharge static HTML files into web apps without script or builds.

66 lines (60 loc) 1.78 kB
/*! * NENT 2022 */ 'use strict'; 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;