How to use @lwc/wire-service - 6 common examples

To help you get started, we’ve selected a few @lwc/wire-service examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pmdartus / rcast / src / client / main.js View on Github external
function init() {
    registerWireService(register);

    document.body.appendChild(
        createElement('rcast-app', {
            is: App,
            fallback: false,
        }),
    );
}
github salesforce / wire-service-jest-util / src / index.js View on Github external
function ensureWireServiceRegistered() {
    if (!registered) {
        registerWireService(register);
        registered = true;
    }
}
github salesforce / wire-service-jest-util / src / adapters / lds.js View on Github external
register(adapterId, (wiredEventTarget) => {
        done = false;
        add(wiredEventTargets, wiredEventTarget);
        wiredEventTarget.dispatchEvent(new ValueChangedEvent({ data: undefined, error: undefined }));

        wiredEventTarget.addEventListener('connect', () => {
            done = false;
            lastConfig = {};
            add(wiredEventTargets, wiredEventTarget);
        });

        wiredEventTarget.addEventListener('disconnect', () => {
            done = true;
            lastConfig = undefined;
            const idx = wiredEventTargets.indexOf(wiredEventTarget);
            if (idx > -1) {
                wiredEventTargets.splice(idx, 1);
            }
        });
github pmdartus / rcast / src / client / modules / store / store / wire-adapter.js View on Github external
const notifyStateChange = () => {
        const state = store.getState();
        eventTarget.dispatchEvent(new ValueChangedEvent(state));
    };
github salesforce / wire-service-jest-util / src / adapters / lds.js View on Github external
wiredEventTargets.forEach(wiredEventTarget => wiredEventTarget.dispatchEvent(new ValueChangedEvent({ data: undefined, error: err })));
        }
    };

    const getLastConfig = () => {
        return lastConfig;
    };

    const add = (arr, item) => {
        const idx = arr.indexOf(item);
        if (idx === -1) {
            arr.push(item);
        }
    };

    register(adapterId, (wiredEventTarget) => {
        done = false;
        add(wiredEventTargets, wiredEventTarget);
        wiredEventTarget.dispatchEvent(new ValueChangedEvent({ data: undefined, error: undefined }));

        wiredEventTarget.addEventListener('connect', () => {
            done = false;
            lastConfig = {};
            add(wiredEventTargets, wiredEventTarget);
        });

        wiredEventTarget.addEventListener('disconnect', () => {
            done = true;
            lastConfig = undefined;
            const idx = wiredEventTargets.indexOf(wiredEventTarget);
            if (idx > -1) {
                wiredEventTargets.splice(idx, 1);
github pmdartus / rcast / src / client / modules / store / store / wire-adapter.js View on Github external
import { register, ValueChangedEvent } from '@lwc/wire-service';

export function connectStore(store) {
    return store.getState();
}

register(connectStore, eventTarget => {
    let store;
    let subscription;

    const notifyStateChange = () => {
        const state = store.getState();
        eventTarget.dispatchEvent(new ValueChangedEvent(state));
    };

    eventTarget.addEventListener('connect', () => {
        subscription = store.subscribe(notifyStateChange);
        notifyStateChange();
    });

    eventTarget.addEventListener('disconnect', () => {
        if (subscription) {
            subscription();

@lwc/wire-service

@wire service

MIT
Latest version published 2 days ago

Package Health Score

90 / 100
Full package analysis