import { UmbStoreUpdateEvent } from './events/index.js';
import { UmbContextBase } from '../../../libs/class-api/index.js';
import { UmbObjectState } from '../../../libs/observable-api/index.js';
/**
 * The base class for a store that holds an object.
 */
export class UmbStoreObjectBase extends UmbContextBase {
    constructor(host, storeAlias, initialData) {
        super(host, storeAlias);
        this._data = new UmbObjectState(initialData ?? null);
    }
    /**
     * Updates the store with the given data
     * @param data - The (partial) data to update the store with
     * @memberof UmbStoreObjectBase
     */
    update(data) {
        this._data.update(data);
        this.dispatchEvent(new UmbStoreUpdateEvent([]));
    }
    /**
     * Returns the current state of the store
     * @memberof UmbStoreObjectBase
     */
    getState() {
        return this._data.getValue();
    }
    /**
     * Returns an observable of the store
     * @memberof UmbStoreObjectBase
     */
    all() {
        return this._data.asObservable();
    }
    /**
     * Returns an observable of a part of the store
     * @param key - The key of the part to return
     * @memberof UmbStoreObjectBase
     */
    part(key) {
        return this._data.asObservablePart((data) => data[key]);
    }
    /**
     * Destroys the store
     * @memberof UmbStoreObjectBase
     */
    destroy() {
        this._data.destroy();
    }
}
