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.

4 lines 1.34 kB
/*! * NENT 2022 */ import{e,E as r}from"./index-f7016b94.js";import{D as o}from"./interfaces-8c5cd1b8.js";import{c as i}from"./index-4bfabbbd.js";import{r as t}from"./values-ddfac998.js";import{d as s}from"./promises-584c4ece.js";import{f as a}from"./logging-5a93c8af.js";const d=i({debug:!1,providers:{},providerTimeout:1}),{state:n}=d,c={},f=new r;function m(r,i){var d;if(t(r,"provider name"),"function"!=typeof i.get)throw new TypeError(`The provider ${r} is missing the get(key) function.`);const m=s(1e3,((...i)=>{e.emit(o.DataChanged,{provider:r,data:i})}),!1),p=null===(d=i.changed)||void 0===d?void 0:d.on("*",((...e)=>{m(e)}));c[r]=p,n.providers[r.toLowerCase()]=i,f.emit("new-provider-added",r.toLocaleLowerCase()),a(n.debug&&"data"!==r,`data-provider: ${r} registered`)}async function p(e){const r=e.toLowerCase();return t(e,"provider name"),Object.keys(n.providers).includes(r)?n.providers[r]:new Promise((o=>{const i=setTimeout((()=>{o(null)}),1e3*n.providerTimeout),t=f.on("new-provider-added",(s=>{e==s&&(clearTimeout(i),t(),o(n.providers[r]))}))}))}function v(e){var r;delete n.providers[e],null===(r=c[e])||void 0===r||r.call(this),delete c[e]}function u(){Object.keys(n.providers).forEach((e=>{var r;null===(r=c[e])||void 0===r||r.call(this),delete c[e],delete n.providers[e]}))}export{m as a,u as c,p as g,v as r,n as s}