import { __flush } from "./scheduler.js"; class Store { constructor(initialState, options) { this.listeners = /* @__PURE__ */ new Set(); this.subscribe = (listener) => { var _a, _b; this.listeners.add(listener); const unsub = (_b = (_a = this.options) == null ? void 0 : _a.onSubscribe) == null ? void 0 : _b.call(_a, listener, this); return () => { this.listeners.delete(listener); unsub == null ? void 0 : unsub(); }; }; this.setState = (updater) => { var _a, _b, _c; this.prevState = this.state; this.state = ((_a = this.options) == null ? void 0 : _a.updateFn) ? this.options.updateFn(this.prevState)(updater) : updater(this.prevState); (_c = (_b = this.options) == null ? void 0 : _b.onUpdate) == null ? void 0 : _c.call(_b); __flush(this); }; this.prevState = initialState; this.state = initialState; this.options = options; } } export { Store }; //# sourceMappingURL=store.js.map