UNPKG

@synergy-design-system/components

Version:

This package provides the base of the Synergy Design System as native web components. It uses [lit](https://www.lit.dev) and parts of [shoelace](https://shoelace.style/). Synergy officially supports the latest two versions of all major browsers (as define

60 lines (59 loc) 2.07 kB
import type SynergyElement from './synergy-element.js'; type Constructor<T = object> = new (...args: any[]) => T; interface DecoratorOptions { /** * If true, will only start watching after the initial updated call */ waitUntilFirstUpdated?: boolean; } /** * Class decorator that automatically emits a `syn-attributes-changed` event * when at least one of the provided attributes have changed. * The event will contain an array of all changed properties, including their * - attribute name * - old value and * - new value. * * @example * ```ts * class OriginalClass extends SynergyElement {} * export const MyComponent = emitEventForPropertyUpdates(['attribute1', 'attribute2'])(BaseClass); * * // Create the component, providing initial values for the changed attribute list * const myComponent = document.createElement('my-component'); * myComponent.attribute1 = 'initial value for attribute 1'; * myComponent.attribute2 = 'initial value for attribute 2'; * * // Create a container and listen for the event * const container = document.createElement('div'); * container.addEventListener('syn-attributes-changed', (event: SynAttributesChangedEvent) => { * // We do not want to propagate the event further * event.stopImmidiatePropagation(); * * console.log(event.detail); * }); * * // Add the component to the container * container.appendChild(myComponent); * * // Change the attributes * myComponent.attribute1 = 'value for attribute 1'; * myComponent.attribute2 = 'value for attribute 2'; * * // Output: * // [ * // { * // attribute: 'attribute1', * // oldValue: 'initial value for attribute 1', * // newValue: 'value for attribute 1' * // }, * // { * // attribute: 'attribute2', * // oldValue: 'initial value for attribute 2', * // newValue: 'value for attribute 2' * // } * // ] * ``` */ export declare function emitEventForPropertyUpdates(watchedProperties: string[], options?: DecoratorOptions): <T extends Constructor<SynergyElement>>(Proto: T) => T; export {};