open-index/open-npm huggingface dataset:
npm package: @kdcloudjs/kwc-signals
Description: Provides the interface to interact with reactivity from outside the framework
Latest version: 1.0.1

# @kdcloudjs/kwc-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 KWC class member variable and used on a template,
the KWC 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.

```js
import { signal } from 'some/signals';

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

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

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

```html
<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 KWC engine expects.

```js
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.

```js
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();
        }
    }
}
```
npm package: @kdcloudjs/kwc-synthetic-shadow
Description: Synthetic Shadow Root for KWC
Latest version: 1.0.0

# Synthetic Shadow Root

## Summary

This is a polyfill for ShadowRoot that was tailor-made for KWC in order to meet the performance goals of the Lightning Platform. This doesn't mean that it cannot be used with any other framework, but we took shortcuts and made compromises that might not align well with other frameworks.

## Compromises

- Default content for `<slot>` elements is always empty.
- `slotchange` is only available directly on the `<slot>` (it doesn't bubble as in the case of the native implementation). This restriction is in place because implementing `slotchange` requires using `MutationObserver` which is expensive at runtime. By only supporting `slotchange` event applied directly on the `<slot>` element, the KWC engine receives a clear signal that the component author is interested in listening to this event. This avoids spending unnecessary CPU time when the `slotchange` event is never consumed.
- If you use `MutationObserver` to watch changes in a DOM tree, disconnect it or you will cause a memory leak. Note that a component can observe mutations only in its own template. It can't observe mutations within the shadow tree of other custom elements.
npm package: @kdcloudjs/kwc-types
Description: This package provides type definitions for KWC projects written in TypeScript.
Latest version: 1.0.1

# @kdcloudjs/kwc-types

This package provides type definitions for KWC projects written in TypeScript.

## Usage

> [!IMPORTANT]
> If you use the `kwc` package in your project, then HTML and CSS imports will work without any configuration required.

```ts
// ./types/global.d.ts
import '@kdcloudjs/kwc-types';

// my-component.ts
import stylesheet from './my-component.css';
import template from './my-component.html';
```

## Module Definitions

This package provides module definitions for HTML and CSS files, so that they can be imported in KWC component script files.