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.

86 lines (85 loc) 2.53 kB
/*! * NENT 2022 */ import { Component, h, Host, Prop } from '@stencil/core'; import { actionBus, eventBus } from '../../services/actions'; import { debugIf } from '../../services/common/logging'; import { commonState } from '../../services/common/state'; import { clearDataProviders } from '../../services/data/factory'; import { dataState } from '../../services/data/state'; import { DataListener } from './services/actions'; /** * This element enables the Data Provider system. It hosts * the action-listener that registers providers. Add this tag * to that page to enable token-replacement. * * @system data * @extension actions * @extension custom */ export class Data { constructor() { /** * Turn on debugging to get helpful messages from the * data action systems. */ this.debug = false; } componentWillLoad() { debugIf(this.debug, `n-data: registering data listener`); if (this.debug) dataState.debug = true; this.listener = new DataListener(); commonState.dataEnabled = true; if (this.providerTimeout) dataState.providerTimeout = this.providerTimeout; this.listener.initialize(window, actionBus, eventBus); } render() { return (h(Host, null, h("slot", null))); } disconnectedCallback() { this.listener.destroy(); clearDataProviders(); } static get is() { return "n-data"; } static get encapsulation() { return "shadow"; } static get properties() { return { "debug": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Turn on debugging to get helpful messages from the\ndata action systems." }, "attribute": "debug", "reflect": false, "defaultValue": "false" }, "providerTimeout": { "type": "number", "mutable": false, "complexType": { "original": "number", "resolved": "number | undefined", "references": {} }, "required": false, "optional": true, "docs": { "tags": [], "text": "The wait-time, in seconds to wait for\nun-registered data providers found in an expression.\nThis is to accommodate a possible lag between\nevaluation before the first predicate\nand the registration process." }, "attribute": "provider-timeout", "reflect": false } }; } }