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

@lit-labs/task

Package Overview
Dependencies
Maintainers
6
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lit-labs/task

A controller for Lit that renders asynchronous tasks.

  • 1.0.0-pre.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
decreased by-22.72%
Maintainers
6
Weekly downloads
 
Created
Source

@lit-labs/task

A controller for Lit that renders asynchronous tasks.

Overview

Often a Lit element needs to request, process, and render remote data, for example when querying a REST API for data to be displayed. The Task controller provides a simple pattern for encapsulating this behavior in an easily reusable way. The controller integrates with a host Lit element. The user provides a task function and a dependencies function. Whenever the element updates, the dependencies are checked and if any have changed, the task is initiated. The controller requests an update of the element whenever the task status changes. Task status is provided via the TaskStatus object which has values for INITIAL, PENDING, COMPLETE, and ERROR. The task result is available via its value property, or via the error property when an error occurs. The task render method may also be used to easily render different task states. It accepts an object which optionally can implement methods for initial, pending, complete(value), and error(error). These methods typically return a Lit TemplateResult to render

Installation

From inside your project folder, run:

$ npm install @lit-labs/task

Usage

Here's an example:

import {Task, TaskStatus} from '@lit-labs/task';
// ...

class MyElement extends LitElement {

  @state()
  private _userId: number;

  private _apiTask = new Task(
      this,
      ([userId]) =>
        fetch(`//example.com/api/userInfo?${userId}`)
          .then(response => response.json())
      () => [this.userId]
    );

  render() {
    return html`
      <div>User Info</div>
      ${this._apiTask.render({
        pending: html`Loading user info...`;
        complete(user): html`${user.name}`;
      })}
      <!-- ... -->
    `;
  }
}

Contributing

Please see CONTRIBUTING.md.

FAQs

Package last updated on 12 Feb 2021

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