const E = (s) => {
  let e;
  const n = /* @__PURE__ */ new Set(), r = (t, i) => {
    const o = typeof t == "function" ? t(e) : t;
    if (!Object.is(o, e)) {
      const l = e;
      e = i ?? (typeof o != "object" || o === null) ? o : Object.assign({}, e, o), n.forEach((a) => a(e, l));
    }
  }, c = () => e, u = { setState: r, getState: c, subscribe: (t) => (n.add(t), () => n.delete(t)), destroy: () => {
    n.clear();
  } };
  return e = s(r, c, u), u;
}, f = (s) => s ? E(s) : E;
export {
  f as createStore
};
