UNPKG

@zag-js/store

Version:

The reactive store package for zag machines

49 lines (47 loc) 1.85 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/proxy-computed.ts var proxy_computed_exports = {}; __export(proxy_computed_exports, { proxyWithComputed: () => proxyWithComputed }); module.exports = __toCommonJS(proxy_computed_exports); var import_proxy = require("./proxy.js"); function proxyWithComputed(initialObject, computedFns) { const keys = Object.keys(computedFns); keys.forEach((key) => { if (Object.getOwnPropertyDescriptor(initialObject, key)) { throw new Error("object property already defined"); } const computedFn = computedFns[key]; const { get, set } = typeof computedFn === "function" ? { get: computedFn } : computedFn; const desc = {}; desc.get = () => get((0, import_proxy.snapshot)(proxyObject)); if (set) { desc.set = (newValue) => set(proxyObject, newValue); } Object.defineProperty(initialObject, key, desc); }); const proxyObject = (0, import_proxy.proxy)(initialObject); return proxyObject; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { proxyWithComputed });