import LiveState, { LiveStateConfig } from "./LiveState.js"; import 'reflect-metadata'; export declare type LiveStateDecoratorOptions = { /** The end point to connect to, should be a websocket url (ws or wss) */ url?: string; /** The topic for the channel */ topic?: string; /** will be sent as params on channel join */ params?: object; /** A list of property names, each of which will be updated from the state * on any state chnages. */ properties?: Array; /** A list of attribute names, each of which will be updated from the state * on any state chnages. */ attributes?: Array; events?: { send?: Array; receive?: Array; }; /** * This will create an instance in the given scope with the specified name. For * example, a scope of `window` and a name of `liveState` will create `window.liveState` * Instances so provided can be found by other elements using a `context` attribute * whose value matches the `name` used by the provider. This will work regardless of * which element occurs first (or highest) in the DOM */ provide?: { scope: object; name: string | undefined; }; /** This will use an existing liveState instance that has been provided with * the given name, rather than creating one. */ context?: string; }; export declare const extractConfig: (element: any) => LiveStateConfig; export declare const buildLiveState: (element: any, { url, topic, params }: LiveStateDecoratorOptions) => LiveState; /** This typescript class decorator will: * Adds a `connectedCallback` method that sets a `liveState` property and calls `connectElement` * Adds a `disconnectedCallback` method that calls `disconnect` on the `liveState` instance Both will call inherited callbacks. The decorator expects to passed an object with the following properties, all of which are optional: * url * topic * params * provide - share this LiveState instance as a context (see below) * scope * name * context - connect to an existing LiveState instance (see below) * properties - passed into `connectElement` * attributes - passed into `connectElement` * events - passed into `connectElement` ```typescript @liveState({ url: 'http://foo.bar', topic: 'discord_chat:new', properties: ['messages'], events: { send: ['new_message', 'start_chat'] } }) ``` ### Context As of 0.7.0, we now support sharing LiveState instances via a context. The way this works is that one element will provide an instance like so: ```typescript @liveState({ channelName: "todo:all", properties: ['todos'], events: { send: ['add_todo'] }, provide: { scope: window, name: 'todoLiveState' } }) ``` This will cause the LiveState instance to be set on the `window` as `todoLiveState`. An element that wishes to connect to an existing LiveState instance uses the context property: ```typescript @liveState({ events: { send: ['add_todo'] }, context: 'todoLiveState' }) ``` This will find an instance with the specified name (in any scope). This will be handled regardless of order, if the consuming instance is created first a queue of consumers will be created that will be resolved and attached when the providing instance is created. */ export declare function liveState(options: LiveStateDecoratorOptions): (targetClass: Function) => void; /** This decorator, introduced in version 0.8.0, adds the ability to have live state config properties be contributed by the element instance. They will override values from the `liveState` decorator on the class, if used. Example: ```typescript @customElement('join-params') @liveState({topic: 'join_params', properties: ['result']}) export class JoinParamsElement extends LitElement { @property({attribute: 'the-url'}) @liveStateConfig('url') theUrl: string = "foo"; @property({attribute: 'api-key'}) @liveStateConfig('params.api_key') apiKey: string = ''; ``` This will cause the `the-url` attribute of the element to be used as the url to connect to, and the `api-key` attribute to be passed as an `api_key` parameter to the channel join. */ export declare const liveStateConfig: (configProperty: any) => (proto: any, propertyName: any) => void; /** This decorator will cause a property to be updated from the state on any state change. It takes an optional expression to pull the value from the state, otherwise it will assume there exists a property on the state of the same name. Example: ```typescript class DecoratedElement extends LitElement { @liveStateProperty() foo: string = 'bar'; @liveStateProperty('bing.baz.bar') nested: string; } ``` */ export declare const liveStateProperty: (path?: string) => (proto: any, propertyName: any) => void; export default liveState;