Files
med-notes/.pnpm-store/v10/files/d1/f4c4df29cf8123c3c044031c0da623f60f49200c98e404668e327c5b01072a3058ac6a5c255143556ad02e6476481a1ac748f7aa5672a7a94efb2771b03968
2025-05-09 05:30:08 +02:00

30 lines
1.1 KiB
Plaintext

"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const scheduler = require("./scheduler.cjs");
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);
scheduler.__flush(this);
};
this.prevState = initialState;
this.state = initialState;
this.options = options;
}
}
exports.Store = Store;
//# sourceMappingURL=store.cjs.map