import type { Fn, Keys } from "@thi.ng/api"; import type { ISubscribable, StreamObj, StreamObjOpts } from "@thi.ng/rstream"; import type { ComponentLike, IComponent, IMountWithState, NumOrElement } from "./api.js"; import { Component } from "./component.js"; /** * Creates a control component wrapper with an internal stream setup for user * defined keys in the given object. When this component is mounted, it will * call `inner` with an object of key-value streams and then {@link $compile}s * that function's return value as component body. * * @remarks * Uses * [`fromObject`](https://docs.thi.ng/umbrella/rstream/functions/fromObject.html) * for creating the internal key-value streams. These can then be used by * `inner` to produce reactive child elements. The given `src` object is only * used to seed those streams with initial values. The component wrapper can be * updated with new values, using the `.update()` life cycle method with a new * object. * * By default the value streams will only trigger updates if their values have * changed. See * [`StreamObjOpts`](https://docs.thi.ng/umbrella/rstream/interfaces/StreamObjOpts.html) * for more details and options. * * Also see {@link $subObject}. * * @example * ```ts * import { $object, type ComponentLike } from "@thi.ng/rdom"; * * const obj = $object( * // source object (for seeding) * { id: "a", name: "foo", ignore: 23 }, * // create subscriptions for given keys * { keys: ["id", "name"] } * // component factory * async (obj) => ["div", {}, "id: ", obj.id, " name: ", obj.name] * ); * * obj.mount(document.body); * * obj.update({ id: "b", name: "bar" }); * ``` * * @param src - * @param opts - options for `fromObject()` stream setup * @param inner - */ export declare const $object: >(src: T, opts: Partial>, inner: Fn["streams"], Promise>) => $Object; /** * Syntax sugar for a combination of {@link $sub} and {@link $object} to allow * reactive updates of `$object()` components themselves. * * @example * ```ts * import { $subObject, type ComponentLike } from "@thi.ng/rdom"; * import { reactive } from "@thi.ng/rstream"; * * interface Foo { * id: string; * name: string; * } * * const state = reactive({ id: "a", name: "foo" }); * * $subObject( * state, * { keys: ["id", "name"] }, * // component factory * // only executed once, but `obj.id` and `obj.name` are reactive values * async (obj) => ["div", {}, "id: ", obj.id, " name: ", obj.name] * ).mount(document.body); * * // update * state.next({ id: "b", name: "bar" }); * ``` * * @param src - * @param opts - * @param inner - */ export declare const $subObject: >(src: ISubscribable, opts: Partial>, inner: Fn["streams"], Promise>) => IComponent; export declare class $Object> extends Component implements IMountWithState { protected ctor: Fn["streams"], Promise>; protected obj: StreamObj; protected inner?: IComponent; constructor(src: T, opts: Partial>, ctor: Fn["streams"], Promise>); mount(parent: ParentNode, index?: NumOrElement, state?: T): Promise; unmount(): Promise; update(state: T): void; } //# sourceMappingURL=object.d.ts.map