Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zag-js/store

Package Overview
Dependencies
Maintainers
1
Versions
738
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/store - npm Package Compare versions

Comparing version 0.0.0-dev-20230202113057 to 0.0.0-dev-20230203093446

297

dist/index.js

@@ -23,293 +23,12 @@ "use strict";

__export(src_exports, {
proxy: () => proxy,
proxyWithComputed: () => proxyWithComputed,
ref: () => ref,
snapshot: () => snapshot,
subscribe: () => subscribe,
subscribeKey: () => subscribeKey
proxy: () => import_vanilla.proxy,
proxyWithComputed: () => import_utils.proxyWithComputed,
ref: () => import_vanilla.ref,
snapshot: () => import_vanilla.snapshot,
subscribe: () => import_vanilla.subscribe,
subscribeKey: () => import_utils.subscribeKey
});
module.exports = __toCommonJS(src_exports);
// ../../node_modules/.pnpm/valtio@1.9.0/node_modules/valtio/esm/vanilla.mjs
var import_proxy_compare = require("proxy-compare");
var import_meta = {};
var isObject = (x) => typeof x === "object" && x !== null;
var proxyStateMap = /* @__PURE__ */ new WeakMap();
var refSet = /* @__PURE__ */ new WeakSet();
var buildProxyFunction = (objectIs = Object.is, newProxy = (target, handler) => new Proxy(target, handler), canProxy = (x) => isObject(x) && !refSet.has(x) && (Array.isArray(x) || !(Symbol.iterator in x)) && !(x instanceof WeakMap) && !(x instanceof WeakSet) && !(x instanceof Error) && !(x instanceof Number) && !(x instanceof Date) && !(x instanceof String) && !(x instanceof RegExp) && !(x instanceof ArrayBuffer), defaultHandlePromise = (promise) => {
switch (promise.status) {
case "fulfilled":
return promise.value;
case "rejected":
throw promise.reason;
default:
throw promise;
}
}, snapCache = /* @__PURE__ */ new WeakMap(), createSnapshot = (target, version, handlePromise = defaultHandlePromise) => {
const cache = snapCache.get(target);
if ((cache == null ? void 0 : cache[0]) === version) {
return cache[1];
}
const snap = Array.isArray(target) ? [] : Object.create(Object.getPrototypeOf(target));
(0, import_proxy_compare.markToTrack)(snap, true);
snapCache.set(target, [version, snap]);
Reflect.ownKeys(target).forEach((key) => {
const value = Reflect.get(target, key);
if (refSet.has(value)) {
(0, import_proxy_compare.markToTrack)(value, false);
snap[key] = value;
} else if (value instanceof Promise) {
Object.defineProperty(snap, key, {
get() {
return handlePromise(value);
}
});
} else if (proxyStateMap.has(value)) {
snap[key] = snapshot(value, handlePromise);
} else {
snap[key] = value;
}
});
return Object.freeze(snap);
}, proxyCache = /* @__PURE__ */ new WeakMap(), versionHolder = [1, 1], proxyFunction2 = (initialObject) => {
if (!isObject(initialObject)) {
throw new Error("object required");
}
const found = proxyCache.get(initialObject);
if (found) {
return found;
}
let version = versionHolder[0];
const listeners = /* @__PURE__ */ new Set();
const notifyUpdate = (op, nextVersion = ++versionHolder[0]) => {
if (version !== nextVersion) {
version = nextVersion;
listeners.forEach((listener) => listener(op, nextVersion));
}
};
let checkVersion = versionHolder[1];
const ensureVersion = (nextCheckVersion = ++versionHolder[1]) => {
if (checkVersion !== nextCheckVersion && !listeners.size) {
checkVersion = nextCheckVersion;
propProxyStates.forEach(([propProxyState]) => {
const propVersion = propProxyState[1](nextCheckVersion);
if (propVersion > version) {
version = propVersion;
}
});
}
return version;
};
const createPropListener = (prop) => (op, nextVersion) => {
const newOp = [...op];
newOp[1] = [prop, ...newOp[1]];
notifyUpdate(newOp, nextVersion);
};
const propProxyStates = /* @__PURE__ */ new Map();
const addPropListener = (prop, propProxyState) => {
if ((import_meta.env && import_meta.env.MODE) !== "production" && propProxyStates.has(prop)) {
throw new Error("prop listener already exists");
}
if (listeners.size) {
const remove = propProxyState[3](createPropListener(prop));
propProxyStates.set(prop, [propProxyState, remove]);
} else {
propProxyStates.set(prop, [propProxyState]);
}
};
const removePropListener = (prop) => {
var _a;
const entry = propProxyStates.get(prop);
if (entry) {
propProxyStates.delete(prop);
(_a = entry[1]) == null ? void 0 : _a.call(entry);
}
};
const addListener = (listener) => {
listeners.add(listener);
if (listeners.size === 1) {
propProxyStates.forEach(([propProxyState, prevRemove], prop) => {
if ((import_meta.env && import_meta.env.MODE) !== "production" && prevRemove) {
throw new Error("remove already exists");
}
const remove = propProxyState[3](createPropListener(prop));
propProxyStates.set(prop, [propProxyState, remove]);
});
}
const removeListener = () => {
listeners.delete(listener);
if (listeners.size === 0) {
propProxyStates.forEach(([propProxyState, remove], prop) => {
if (remove) {
remove();
propProxyStates.set(prop, [propProxyState]);
}
});
}
};
return removeListener;
};
const baseObject = Array.isArray(initialObject) ? [] : Object.create(Object.getPrototypeOf(initialObject));
const handler = {
deleteProperty(target, prop) {
const prevValue = Reflect.get(target, prop);
removePropListener(prop);
const deleted = Reflect.deleteProperty(target, prop);
if (deleted) {
notifyUpdate(["delete", [prop], prevValue]);
}
return deleted;
},
set(target, prop, value, receiver) {
var _a;
const hasPrevValue = Reflect.has(target, prop);
const prevValue = Reflect.get(target, prop, receiver);
if (hasPrevValue && objectIs(prevValue, value)) {
return true;
}
removePropListener(prop);
if (isObject(value)) {
value = (0, import_proxy_compare.getUntracked)(value) || value;
}
let nextValue = value;
if ((_a = Object.getOwnPropertyDescriptor(target, prop)) == null ? void 0 : _a.set)
;
else if (value instanceof Promise) {
value.then((v) => {
value.status = "fulfilled";
value.value = v;
notifyUpdate(["resolve", [prop], v]);
}).catch((e) => {
value.status = "rejected";
value.reason = e;
notifyUpdate(["reject", [prop], e]);
});
} else {
if (!proxyStateMap.has(value) && canProxy(value)) {
nextValue = proxy(value);
}
const childProxyState = !refSet.has(nextValue) && proxyStateMap.get(nextValue);
if (childProxyState) {
addPropListener(prop, childProxyState);
}
}
Reflect.set(target, prop, nextValue, receiver);
notifyUpdate(["set", [prop], value, prevValue]);
return true;
}
};
const proxyObject = newProxy(baseObject, handler);
proxyCache.set(initialObject, proxyObject);
const proxyState = [
baseObject,
ensureVersion,
createSnapshot,
addListener
];
proxyStateMap.set(proxyObject, proxyState);
Reflect.ownKeys(initialObject).forEach((key) => {
const desc = Object.getOwnPropertyDescriptor(
initialObject,
key
);
if (desc.get || desc.set) {
Object.defineProperty(baseObject, key, desc);
} else {
proxyObject[key] = initialObject[key];
}
});
return proxyObject;
}) => [
proxyFunction2,
proxyStateMap,
refSet,
objectIs,
newProxy,
canProxy,
defaultHandlePromise,
snapCache,
createSnapshot,
proxyCache,
versionHolder
];
var [proxyFunction] = buildProxyFunction();
function proxy(initialObject = {}) {
return proxyFunction(initialObject);
}
function subscribe(proxyObject, callback, notifyInSync) {
const proxyState = proxyStateMap.get(proxyObject);
if ((import_meta.env && import_meta.env.MODE) !== "production" && !proxyState) {
console.warn("Please use proxy object");
}
let promise;
const ops = [];
const addListener = proxyState[3];
let isListenerActive = false;
const listener = (op) => {
ops.push(op);
if (notifyInSync) {
callback(ops.splice(0));
return;
}
if (!promise) {
promise = Promise.resolve().then(() => {
promise = void 0;
if (isListenerActive) {
callback(ops.splice(0));
}
});
}
};
const removeListener = addListener(listener);
isListenerActive = true;
return () => {
isListenerActive = false;
removeListener();
};
}
function snapshot(proxyObject, handlePromise) {
const proxyState = proxyStateMap.get(proxyObject);
if ((import_meta.env && import_meta.env.MODE) !== "production" && !proxyState) {
console.warn("Please use proxy object");
}
const [target, ensureVersion, createSnapshot] = proxyState;
return createSnapshot(target, ensureVersion(), handlePromise);
}
function ref(obj) {
refSet.add(obj);
return obj;
}
// ../../node_modules/.pnpm/valtio@1.9.0/node_modules/valtio/esm/vanilla/utils.mjs
function subscribeKey(proxyObject, key, callback, notifyInSync) {
let prevValue = proxyObject[key];
return subscribe(
proxyObject,
() => {
const nextValue = proxyObject[key];
if (!Object.is(prevValue, nextValue)) {
callback(prevValue = nextValue);
}
},
notifyInSync
);
}
var DEVTOOLS = Symbol();
function proxyWithComputed(initialObject, computedFns) {
Object.keys(computedFns).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(snapshot(proxyObject));
if (set) {
desc.set = (newValue) => set(proxyObject, newValue);
}
Object.defineProperty(initialObject, key, desc);
});
const proxyObject = proxy(initialObject);
return proxyObject;
}
var import_vanilla = require("valtio/vanilla");
var import_utils = require("valtio/utils");
// Annotate the CommonJS export names for ESM import in node:

@@ -316,0 +35,0 @@ 0 && (module.exports = {

8

package.json
{
"name": "@zag-js/store",
"version": "0.0.0-dev-20230202113057",
"version": "0.0.0-dev-20230203093446",
"description": "The reactive store package for zag machines",

@@ -26,3 +26,4 @@ "keywords": [

"dependencies": {
"proxy-compare": "2.4.0"
"proxy-compare": "2.4.0",
"valtio": "^1.9.0"
},

@@ -32,4 +33,3 @@ "clean-package": "../../clean-package.config.json",

"devDependencies": {
"clean-package": "2.2.0",
"valtio": "^1.9.0"
"clean-package": "2.2.0"
},

@@ -36,0 +36,0 @@ "module": "dist/index.mjs",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc