8.6.0 • Published 8 months ago

@lwc/signals v8.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@lwc/signals

This is an experimental package containing the interface expected for signals.

A key point to note is that when a signal is both bound to an LWC class member variable and used on a template, the LWC engine will attempt to subscribe a callback to rerender the template.

Reactivity with Signals

A Signal is an object that holds a value and allows components to react to changes to that value. It exposes a .value property for accessing the current value, and .subscribe methods for responding to changes.

import { signal } from 'some/signals';

export default class ExampleComponent extends LightningElement {
    count = signal(0);

    increment() {
        this.count.value++;
    }
}

In the template, we can bind directly to the .value property:

<template>
    <button onclick="{increment}">Increment</button>
    <p>{count.value}</p>
</template>

Supported APIs

This package supports the following APIs.

Signal

This is the shape of the signal that the LWC engine expects.

export type OnUpdate = () => void;
export type Unsubscribe = () => void;

export interface Signal<T> {
    get value(): T;
    subscribe(onUpdate: OnUpdate): Unsubscribe;
}

SignalBaseClass

A base class is provided as a starting point for implementation.

export abstract class SignalBaseClass<T> implements Signal<T> {
    abstract get value(): T;

    private subscribers: Set<OnUpdate> = new Set();

    subscribe(onUpdate: OnUpdate) {
        this.subscribers.add(onUpdate);
        return () => {
            this.subscribers.delete(onUpdate);
        };
    }

    protected notify() {
        for (const subscriber of this.subscribers) {
            subscriber();
        }
    }
}
8.6.0

8 months ago

8.4.0

8 months ago

8.5.0

8 months ago

8.3.0

9 months ago

8.2.0

9 months ago

8.1.2

9 months ago

8.1.1

9 months ago

8.1.3

9 months ago

7.1.5

9 months ago

8.1.0

10 months ago

8.1.0-alpha.5

10 months ago

8.1.0-alpha.4

10 months ago

8.1.0-alpha.1

10 months ago

8.1.0-alpha.0

10 months ago

8.1.0-alpha.3

10 months ago

8.1.0-alpha.2

10 months ago

8.0.0-alpha.0

10 months ago

8.0.0-alpha.1

10 months ago

7.2.6

10 months ago

7.2.5

10 months ago

7.2.4

10 months ago

7.1.4

10 months ago

8.0.0

10 months ago

7.2.3

10 months ago

7.2.3-alpha.0

10 months ago

7.0.0-alpha.1

1 year ago

7.3.0-alpha.3

11 months ago

7.3.0-alpha.2

11 months ago

7.3.0-alpha.1

12 months ago

7.3.0-alpha.0

12 months ago

7.1.3

11 months ago

7.1.2

12 months ago

7.1.1

12 months ago

7.1.0

12 months ago

7.0.5

12 months ago

6.4.3

1 year ago

6.4.2

1 year ago

6.4.5

1 year ago

6.4.4

1 year ago

6.6.5

1 year ago

6.6.4

1 year ago

6.6.7

1 year ago

6.6.6

1 year ago

7.0.1-alpha.0

1 year ago

7.0.3-alpha.0

1 year ago

7.0.0

1 year ago

7.2.2

11 months ago

7.0.4

12 months ago

7.2.1

11 months ago

7.0.3

1 year ago

7.2.0

12 months ago

7.0.2

1 year ago

7.0.1

1 year ago

6.7.0

1 year ago

6.7.2

1 year ago

6.7.1

1 year ago

7.0.0-alpha.0

1 year ago

6.6.3

1 year ago

6.6.2

1 year ago

6.6.1

1 year ago

6.6.0

1 year ago

6.5.3

1 year ago

6.5.2

1 year ago

6.5.1

1 year ago

6.5.0

1 year ago

6.4.1

1 year ago

6.4.0

1 year ago

6.3.4

1 year ago

6.3.3

1 year ago

6.3.2

1 year ago

6.3.1

1 year ago

6.3.0

1 year ago

6.2.1

1 year ago

6.2.0

1 year ago

0.0.0

1 year ago