Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lwc/wire-service

Package Overview
Dependencies
Maintainers
13
Versions
799
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lwc/wire-service

@wire service

  • 7.0.3-alpha.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
56K
decreased by-30.13%
Maintainers
13
Weekly downloads
 
Created
Source

Wire Service

This code is the implementation of the Lightning Web Component wire service. The wire service enables declarative binding of data providers called wire adapters to a Lightning web component using the @wire decorator. It fulfills the goals of the data service proposal.

Summary

Wire adapters simply provide data. A wire adapter doesn't know anything about the components that it provides data to.

In a component, declare its data needs by using the @wire decorator to connect (or wire) it to a wire adapter. In this example, the component is wired to the getBook wire adapter. This declarative technique makes component code easy to read and reason about.

// bookItem.js
import { LightningElement } from 'lwc';

export default class WireExample extends {
    @api bookId;

    @wire(getBook, { id: '$bookId'})
    book;
}

Wire adapters are part of LWC's reactivity system. An @wire takes the name of a wire adapter and an optional configuration object, which is specific to the wire adapter. You can use a $ to mark the property of a configuration object as reactive. When a reactive property’s value changes, the wire adapter's update method executes with the new value. When the wire adapter provisions new data, the component rerenders if necessary.

// wire-adapter.js
import { bookEndpoint } from './server';

export class getBook {
    connected = false;
    bookId;

    constructor(dataCallback) {
        this.dataCallback = dataCallback;
    }

    connect() {
        this.connected = true;
        this.provideBookWithId(this.bookId);
    }

    disconnect() {
        this.connected = false;
    }

    update(config) {
        if (this.bookId !== config.id) {
            this.bookId = config.id;
            this.provideBookWithId(this.bookId);
        }
    }

    provideBookWithId(id) {
        if (this.connected && this.bookId !== undefined) {
            const book = bookEndpoint.getById(id);

            if (book) {
                this.dataCallback(Object.assign({}, book));
            } else {
                this.dataCallback(null);
            }
        }
    }
}

Syntax

For complete information about syntax, see lwc.dev/guide/wire_adapter.

Implementation Example

The RCast App is a PWA podcast player written with Lightning Web Components.

https://github.com/pmdartus/rcast

Keywords

FAQs

Package last updated on 02 Jul 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