New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@helga-agency/async-loader

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@helga-agency/async-loader

Custom element that loads content through XHR

  • 1.8.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

Async Loader

Component that fetches contents asynchronously and displays it when ready:

  • support loading indicator
  • supports error handling

Example

<async-loader
    data-endpoint-url="/testContent.html"
    data-trigger-event-names="loadData1,loadData2"
    data-trigger-event-filter="(event.type === 'loadData1' && event.detail.loadAsync === true) || event.type === 'loadData2'"
>
    <div data-content-container>Initial Content</div>
    <template data-loading-template>Loading ...</template>
    <template data-error-template>Error: {{message}}</template>
</async-loader>

<button class="regularContentButton">Load</button>

<script>
    document.querySelector('.regularContentButton').addEventListener('click', () => {
        const options = { bubbles: true, detail: { loadAsync: true } };
        window.dispatchEvent(new CustomEvent('loadData', options));
    });
</script>

Components

Async Loader

Exposed Element

<async-loader></async-loader>

Attributes
  • data-endpoint-url (required if data-event-endpoint-property-name is not set): URL that should be fetched. If both data-endpoint-url and data-event-endpoint-property-name are provided, data-endpoint-url will be preferred.
  • data-trigger-event-name (deprecated): Name of the event that causes content to be loaded; it will be listened to on window.
  • data-trigger-event-names (required): Comma separated names of the events which will trigger the fetching of the content; they will be listened to on window.
  • data-event-endpoint-property-name (required if data-endpoint-url is not set): Name of the property in the event payload (detail property of the event object) which contains the endpoint URL. Has no effect if data-endpoint-url is set.
  • data-trigger-event-filter (optional): JavaScript expression that will be evaluated against the event if provided. Only if the event matches the expression, data will be loaded; if not, the event will be ignored. Only one variable is passed (the Event thats name matches data-trigger-event-name); it can be accessed through event.
  • data-load-once (optional): if this boolean attribute is set, content will load only once, no matter how many times a valid event fires.
Content

The following elements may or must be provided within <aync-loader>:

  • Any element matching [data-content-container] (required): Content (loading, error or successfully fetched content) will be placed within this element after it has been emptied.
  • A template element that matches [data-loading-template] (optional): Its content will be displayed within [data-content-container] while data is loading.
  • A template element that matches [data-error-template] (required): Its content will be displayed within [data-content-container] if loading data fails; you may use a string {{message}} within the template's textContent to display the error message.

Events

  • Dispatches asyncLoaderFail event if loading content fails (bubbles).
  • Dispatches asyncLoaderSuccess event if loading content succeeds (bubbles).
  • Both events carry a detail object with properties url (String, deprecated), response (instance of Response) and element (HTMLElement that matches the dispatching AsyncLoader).

FAQs

Package last updated on 09 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc