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.44 kB
/*! * NENT 2022 */ import{r as s,a as i}from"./index-916ca544.js";import{a as t,e as r}from"./index-f7016b94.js";import{a,r as o}from"./factory-acbf0d3d.js";import{D as e}from"./interfaces-4b724211.js";import{D as n}from"./interfaces-8c5cd1b8.js";import"./index-4bfabbbd.js";import"./values-ddfac998.js";import"./promises-584c4ece.js";import"./logging-5a93c8af.js";class h{constructor(s,i,t,r=""){this.eventBus=i,this.name=t,this.prefix=r,this.localStorage=s.localStorage,null===window||void 0===window||window.addEventListener("storage",(()=>{this.eventBus.emit(n.DataChanged,{provider:this.name})}),{passive:!0})}async get(s){var i;return(null===(i=this.localStorage)||void 0===i?void 0:i.getItem(this.prefix+s))||null}async set(s,i){var t;await this.get(s)!=i&&(null===(t=this.localStorage)||void 0===t||t.setItem(this.prefix+s,i),this.eventBus.emit(n.DataChanged,{provider:this.name}))}}const c=class{constructor(i){s(this,i),this.name="storage"}registerProvider(){a(this.name,this.provider),this.actionSubscription=t.on(this.name,(async s=>{if(s.command==e.SetData){const{data:i}=s;await Promise.all(Object.keys(s.data).map((s=>this.provider.set(s,i[s]))))}}))}componentWillLoad(){this.provider=new h(window,r,this.name,this.keyPrefix),this.registerProvider()}disconnectedCallback(){var s;o(this.name),null===(s=this.actionSubscription)||void 0===s||s.call(this)}render(){return null}get el(){return i(this)}};export{c as n_data_storage}