//#region src/stream/store.ts
var StreamStore = class {
	#snapshot;
	#listeners = /* @__PURE__ */ new Set();
	constructor(initial) {
		this.#snapshot = initial;
	}
	subscribe = (listener) => {
		this.#listeners.add(listener);
		return () => {
			this.#listeners.delete(listener);
		};
	};
	getSnapshot = () => this.#snapshot;
	/** Replace the snapshot and notify every listener. */
	setValue = (next) => {
		if (Object.is(next, this.#snapshot)) return;
		this.#snapshot = next;
		for (const listener of this.#listeners) listener();
	};
	/**
	* Functional update. The `updater` receives the current snapshot and
	* MUST return a new object. Returning the same reference is a no-op.
	*/
	setState = (updater) => {
		this.setValue(updater(this.#snapshot));
	};
};
//#endregion
exports.StreamStore = StreamStore;

//# sourceMappingURL=store.cjs.map