Socket
Socket
Sign inDemoInstall

valtio

Package Overview
Dependencies
Maintainers
2
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

valtio - npm Package Compare versions

Comparing version 1.6.1 to 1.6.2

10

esm/react.d.ts

@@ -1,11 +0,9 @@

declare type AsRef = {
$$valtioRef: true;
};
import type { INTERNAL_AsRef } from './vanilla';
declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;
};
declare type Options = {
interface Options {
sync?: boolean;
};
}
/**

@@ -12,0 +10,0 @@ * useSnapshot

4

esm/utils.js

@@ -68,3 +68,3 @@ import { subscribe, snapshot, proxy, getVersion, ref } from 'valtio/vanilla';

if (typeof options === "string") {
console.warn("[Deprecated] Please use option object instead of name string");
console.warn("string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400");
options = { name: options };

@@ -334,3 +334,3 @@ }

function addComputed_DEPRECATED(proxyObject, computedFns_FAKE, targetObject = proxyObject) {
console.warn("addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive.");
console.warn("addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201");
const derivedFns = {};

@@ -337,0 +337,0 @@ Object.keys(computedFns_FAKE).forEach((key) => {

declare type DeriveGet = <T extends object>(proxyObject: T) => T;
declare type Subscription = {
interface Subscription {
s: object;

@@ -10,3 +10,3 @@ d: object;

p?: Promise<void>;
};
}
export declare const unstable_deriveSubscriptions: {

@@ -13,0 +13,0 @@ add: (subscription: Subscription) => void;

@@ -1,5 +0,5 @@

declare type Options = {
interface Options {
enabled?: boolean;
name?: string;
};
}
export declare function devtools<T extends object>(proxyObject: T, options?: Options): (() => void) | undefined;

@@ -6,0 +6,0 @@ /**

@@ -1,6 +0,4 @@

declare type AsRef = {
$$valtioRef: true;
};
import type { INTERNAL_AsRef } from '../vanilla';
declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;

@@ -7,0 +5,0 @@ };

declare type Cleanup = () => void;
declare type WatchGet = <T extends object>(proxyObject: T) => T;
declare type WatchCallback = (get: WatchGet) => Cleanup | void | undefined;
declare type WatchOptions = {
interface WatchOptions {
sync?: boolean;
};
}
/**

@@ -8,0 +8,0 @@ * watch

@@ -1,5 +0,9 @@

declare type AsRef = {
/**
* This not a public API.
* It can be changed without notice.
*/
export interface INTERNAL_AsRef {
$$valtioRef: true;
};
export declare function ref<T extends object>(o: T): T & AsRef;
}
export declare function ref<T extends object>(o: T): T & INTERNAL_AsRef;
declare type Path = (string | symbol)[];

@@ -11,3 +15,3 @@ declare type Op = [op: 'set', path: Path, value: unknown, prevValue: unknown] | [op: 'delete', path: Path, prevValue: unknown] | [op: 'resolve', path: Path, value: unknown] | [op: 'reject', path: Path, error: unknown];

declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;

@@ -14,0 +18,0 @@ };

{
"name": "valtio",
"private": false,
"version": "1.6.1",
"version": "1.6.2",
"description": "💊 Valtio makes proxy-state simple for React and Vanilla",

@@ -79,4 +79,4 @@ "main": "./index.js",

"dependencies": {
"proxy-compare": "2.1.0",
"use-sync-external-store": "1.1.0"
"proxy-compare": "2.2.0",
"use-sync-external-store": "1.2.0"
},

@@ -83,0 +83,0 @@ "resolutions": {

@@ -1,11 +0,9 @@

declare type AsRef = {
$$valtioRef: true;
};
import type { INTERNAL_AsRef } from './vanilla';
declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;
};
declare type Options = {
interface Options {
sync?: boolean;
};
}
/**

@@ -12,0 +10,0 @@ * useSnapshot

@@ -122,3 +122,3 @@ <img src="logo.svg" alt="valtio">

// Suscribe to all state changes
// Subscribe to all state changes
const unsubscribe = subscribe(state, () =>

@@ -201,3 +201,3 @@ console.log('state has changed to', state)

#### Update transiently (for often occuring state-changes)
#### Update transiently (for often occurring state-changes)

@@ -458,2 +458,12 @@ You can read state in a component without causing re-render.

#### Compatibility
Valtio works with React with hooks support (>=16.8).
It only depends on `react` and works with any
renderers such as `react-dom`, `react-native`, `react-three-fiber`, and so on.
Valtio works on Node.js, Next.js and other frameworks.
Valtio also works without React. See [vanilla](#use-it-vanilla).
#### Plugins

@@ -472,17 +482,1 @@

- [How to split and compose states](https://github.com/pmndrs/valtio/wiki/How-to-split-and-compose-states)
---
## How to contribute
### Basic things to know before adding docs
- Docs live in `docs/` folder.
- Website lives in `website/` folder.
- Docs are written in `mdx` format.
- Docs filename shouldn't have spaces.
- Website would generate title and other metadata from graymatter in the file.
- You should be able to render condesandbox inside `mdx` files by simply adding the url for the same
- Once you have a doc, you can add it to the sidebar section by adding it to the nav in `getDocsNav` function inside `website/lib/mdx.ts`
---

@@ -1,1 +0,1 @@

System.register(["react","proxy-compare","use-sync-external-store/shim","valtio/vanilla"],function(u){"use strict";var s,o,i,f,p,b,h,y,c;return{setters:[function(e){s=e.useRef,o=e.useCallback,i=e.useEffect,f=e.useMemo},function(e){p=e.isChanged,b=e.createProxy},function(e){h=e.default},function(e){y=e.subscribe,c=e.snapshot,u({getVersion:e.getVersion,proxy:e.proxy,ref:e.ref,snapshot:e.snapshot,subscribe:e.subscribe,unstable_getHandler:e.getHandler})}],execute:function(){u("useSnapshot",S);const{useSyncExternalStore:e}=h;function S(t,x){const g=x==null?void 0:x.sync,r=s(),a=s();let k=!0;const l=e(o(n=>{const C=y(t,n,g);return n(),C},[t,g]),()=>{const n=c(t);try{if(!k&&r.current&&a.current&&!p(r.current,n,a.current,new WeakMap))return r.current}catch{}return n},()=>c(t));k=!1;const M=new WeakMap;i(()=>{r.current=l,a.current=M});const v=f(()=>new WeakMap,[]);return b(l,M,v)}}}});
System.register(["react","proxy-compare","use-sync-external-store/shim","valtio/vanilla"],function(u){"use strict";var s,o,i,f,p,b,h,y,c;return{setters:[function(e){s=e.useRef,o=e.useCallback,i=e.useEffect,f=e.useMemo},function(e){p=e.isChanged,b=e.createProxy},function(e){h=e.default},function(e){y=e.subscribe,c=e.snapshot,u({getVersion:e.getVersion,proxy:e.proxy,ref:e.ref,snapshot:e.snapshot,subscribe:e.subscribe,unstable_getHandler:e.getHandler})}],execute:function(){u("useSnapshot",S);const{useSyncExternalStore:e}=h;function S(n,g){const x=g==null?void 0:g.sync,r=s(),a=s();let k=!0;const l=e(o(t=>{const C=y(n,t,x);return t(),C},[n,x]),()=>{const t=c(n);try{if(!k&&r.current&&a.current&&!p(r.current,t,a.current,new WeakMap))return r.current}catch{}return t},()=>c(n));k=!1;const M=new WeakMap;i(()=>{r.current=l,a.current=M});const v=f(()=>new WeakMap,[]);return b(l,M,v)}}}});

@@ -92,3 +92,3 @@ System.register(['valtio/vanilla'], (function (exports) {

if (typeof options === "string") {
console.warn("[Deprecated] Please use option object instead of name string");
console.warn("string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400");
options = { name: options };

@@ -358,3 +358,3 @@ }

function addComputed_DEPRECATED(proxyObject, computedFns_FAKE, targetObject = proxyObject) {
console.warn("addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive.");
console.warn("addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201");
const derivedFns = {};

@@ -361,0 +361,0 @@ Object.keys(computedFns_FAKE).forEach((key) => {

@@ -1,2 +0,2 @@

System.register(["valtio/vanilla"],function(A){"use strict";var g,y,v,x,k;return{setters:[function(b){g=b.subscribe,y=b.snapshot,v=b.proxy,x=b.getVersion,k=b.ref}],execute:function(){A({addComputed:W,derive:D,devtools:J,proxyMap:V,proxySet:L,proxyWithComputed:R,proxyWithHistory:U,subscribeKey:b,underive:z,watch:I});function b(n,s,e,t){return g(n,r=>{r.some(o=>o[1][0]===s)&&e(n[s])},t)}let O;function I(n,s){let e=!0;const t=new Set,r=new Map,o=()=>{e&&(e=!1,t.forEach(i=>i()),t.clear(),r.forEach(i=>i()),r.clear())},l=()=>{if(!e)return;t.forEach(a=>a()),t.clear();const i=new Set,u=O;O=t;try{const a=n(c=>(i.add(c),c));a&&t.add(a)}finally{O=u}r.forEach((a,c)=>{i.has(c)?i.delete(c):(r.delete(c),a())}),i.forEach(a=>{const c=g(a,l,s==null?void 0:s.sync);r.set(a,c)})};return O&&O.add(o),l(),o}const j=Symbol();function J(n,s){typeof s=="string"&&(console.warn("[Deprecated] Please use option object instead of name string"),s={name:s});const{enabled:e,name:t=""}=s||{};let r;try{r=(e!=null?e:!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!r)return;let o=!1;const l=r.connect({name:t}),i=g(n,a=>{const c=a.filter(([h,d])=>d[0]!==j).map(([h,d])=>`${h}:${d.map(String).join(".")}`).join(", ");if(c)if(o)o=!1;else{const h=Object.assign({},y(n));delete h[j],l.send({type:c,updatedAt:new Date().toLocaleString()},h)}}),u=l.subscribe(a=>{var c,h,d,p,E,w;if(a.type==="ACTION"&&a.payload)try{Object.assign(n,JSON.parse(a.payload))}catch(f){console.error(`please dispatch a serializable value that JSON.parse() and proxy() support
`,f)}if(a.type==="DISPATCH"&&a.state){if(((c=a.payload)==null?void 0:c.type)==="JUMP_TO_ACTION"||((h=a.payload)==null?void 0:h.type)==="JUMP_TO_STATE"){o=!0;const f=JSON.parse(a.state);Object.assign(n,f)}n[j]=a}else if(a.type==="DISPATCH"&&((d=a.payload)==null?void 0:d.type)==="COMMIT")l.init(y(n));else if(a.type==="DISPATCH"&&((p=a.payload)==null?void 0:p.type)==="IMPORT_STATE"){const f=(E=a.payload.nextLiftedState)==null?void 0:E.actionsById,K=((w=a.payload.nextLiftedState)==null?void 0:w.computedStates)||[];o=!0,K.forEach(({state:X},N)=>{const $=f[N]||"No action found";Object.assign(n,X),N===0?l.init(y(n)):l.send($,y(n))})}});return l.init(y(n)),()=>{i(),u==null||u()}}const S=new WeakMap,m=new WeakMap,C=(n,s)=>{const e=S.get(n);e&&(e[0].forEach(t=>{const{d:r}=t;n!==r&&C(r)}),++e[2],s&&e[3].add(s))},H=(n,s)=>{const e=S.get(n);return e!=null&&e[2]?(e[3].add(s),!0):!1},T=n=>{const s=S.get(n);s&&(--s[2],s[2]||(s[3].forEach(e=>e()),s[3].clear()),s[0].forEach(e=>{const{d:t}=e;n!==t&&T(t)}))},M=n=>{const{s,d:e}=n;let t=m.get(e);t||(t=[new Set],m.set(n.d,t)),t[0].add(n);let r=S.get(s);if(!r){const o=new Set,l=g(s,i=>{o.forEach(u=>{const{d:a,c,n:h,i:d}=u;s===a&&i.every(p=>p[1].length===1&&d.includes(p[1][0]))||u.p||(C(s,c),h?T(s):u.p=Promise.resolve().then(()=>{delete u.p,T(s)}))})},!0);r=[o,l,0,new Set],S.set(s,r)}r[0].add(n)},P=n=>{const{s,d:e}=n,t=m.get(e);t==null||t[0].delete(n),(t==null?void 0:t[0].size)===0&&m.delete(e);const r=S.get(s);if(r){const[o,l]=r;o.delete(n),o.size||(l(),S.delete(s))}},_=n=>{const s=m.get(n);return s?Array.from(s[0]):[]},B=A("unstable_deriveSubscriptions",{add:M,remove:P,list:_});function D(n,s){const e=(s==null?void 0:s.proxy)||v({}),t=!!(s!=null&&s.sync),r=Object.keys(n);return r.forEach(o=>{if(Object.getOwnPropertyDescriptor(e,o))throw new Error("object property already defined");const l=n[o];let i=null;const u=()=>{if(i&&(Array.from(i).map(([d])=>H(d,u)).some(d=>d)||Array.from(i).every(([d,p])=>x(d)===p.v)))return;const a=new Map,c=l(d=>(a.set(d,{v:x(d)}),d)),h=()=>{a.forEach((d,p)=>{var E;const w=(E=i==null?void 0:i.get(p))==null?void 0:E.s;if(w)d.s=w;else{const f={s:p,d:e,k:o,c:u,n:t,i:r};M(f),d.s=f}}),i==null||i.forEach((d,p)=>{!a.has(p)&&d.s&&P(d.s)}),i=a};c instanceof Promise?c.finally(h):h(),e[o]=c};u()}),e}function z(n,s){const e=s!=null&&s.delete?new Set:null;_(n).forEach(t=>{const{k:r}=t;(!(s!=null&&s.keys)||s.keys.includes(r))&&(P(t),e&&e.add(r))}),e&&e.forEach(t=>{delete n[t]})}function W(n,s,e=n){console.warn("addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive.");const t={};return Object.keys(s).forEach(r=>{t[r]=o=>s[r](o(n))}),D(t,{proxy:e})}function R(n,s){Object.keys(s).forEach(t=>{if(Object.getOwnPropertyDescriptor(n,t))throw new Error("object property already defined");const r=s[t],{get:o,set:l}=typeof r=="function"?{get:r}:r,i={};i.get=()=>o(y(e)),l&&(i.set=u=>l(e,u)),Object.defineProperty(n,t,i)});const e=v(n);return e}function U(n,s=!1){const e=v({value:n,history:k({wip:n,snapshots:[],index:-1}),canUndo:()=>e.history.index>0,undo:()=>{e.canUndo()&&(e.value=e.history.wip=e.history.snapshots[--e.history.index],e.history.snapshots[e.history.index]=y(e).value)},canRedo:()=>e.history.index<e.history.snapshots.length-1,redo:()=>{e.canRedo()&&(e.value=e.history.wip=e.history.snapshots[++e.history.index],e.history.snapshots[e.history.index]=y(e).value)},saveHistory:()=>{e.history.snapshots.splice(e.history.index+1),e.history.snapshots.push(y(e).value),++e.history.index},subscribe:()=>g(e,t=>{t.every(r=>r[1][0]==="value"&&(r[0]!=="set"||r[2]!==e.history.wip))&&e.saveHistory()})});return e.saveHistory(),s||e.subscribe(),e}function L(n){const s=v({data:Array.from(new Set(n)),has(e){return this.data.indexOf(e)!==-1},add(e){let t=!1;return typeof e=="object"&&e!==null&&(t=this.data.indexOf(v(e))!==-1),this.data.indexOf(e)===-1&&!t&&this.data.push(e),this},delete(e){const t=this.data.indexOf(e);return t===-1?!1:(this.data.splice(t,1),!0)},clear(){this.data.splice(0)},get size(){return this.data.length},forEach(e){this.data.forEach(t=>{e(t,t,this)})},get[Symbol.toStringTag](){return"Set"},toJSON(){return{}},[Symbol.iterator](){return this.data[Symbol.iterator]()},values(){return this.data.values()},keys(){return this.data.values()},entries(){return new Set(this.data).entries()}});return Object.defineProperties(s,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(s),s}function V(n){const s=v({data:Array.from(n||[]),has(e){return this.data.some(t=>t[0]===e)},set(e,t){const r=this.data.find(o=>o[0]===e);return r?r[1]=t:this.data.push([e,t]),this},get(e){var t;return(t=this.data.find(r=>r[0]===e))==null?void 0:t[1]},delete(e){const t=this.data.findIndex(r=>r[0]===e);return t===-1?!1:(this.data.splice(t,1),!0)},clear(){this.data.splice(0)},get size(){return this.data.length},toJSON(){return{}},forEach(e){this.data.forEach(t=>{e(t[1],t[0],this)})},keys(){return this.data.map(e=>e[0]).values()},values(){return this.data.map(e=>e[1]).values()},entries(){return new Map(this.data).entries()},get[Symbol.toStringTag](){return"Map"},[Symbol.iterator](){return this.entries()}});return Object.defineProperties(s,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(s),s}}}});
System.register(["valtio/vanilla"],function(A){"use strict";var m,y,v,x,k;return{setters:[function(b){m=b.subscribe,y=b.snapshot,v=b.proxy,x=b.getVersion,k=b.ref}],execute:function(){A({addComputed:W,derive:N,devtools:J,proxyMap:V,proxySet:L,proxyWithComputed:R,proxyWithHistory:U,subscribeKey:b,underive:z,watch:I});function b(n,s,e,t){return m(n,r=>{r.some(o=>o[1][0]===s)&&e(n[s])},t)}let S;function I(n,s){let e=!0;const t=new Set,r=new Map,o=()=>{e&&(e=!1,t.forEach(i=>i()),t.clear(),r.forEach(i=>i()),r.clear())},l=()=>{if(!e)return;t.forEach(a=>a()),t.clear();const i=new Set,u=S;S=t;try{const a=n(d=>(i.add(d),d));a&&t.add(a)}finally{S=u}r.forEach((a,d)=>{i.has(d)?i.delete(d):(r.delete(d),a())}),i.forEach(a=>{const d=m(a,l,s==null?void 0:s.sync);r.set(a,d)})};return S&&S.add(o),l(),o}const j=Symbol();function J(n,s){typeof s=="string"&&(console.warn("string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400"),s={name:s});const{enabled:e,name:t=""}=s||{};let r;try{r=(e!=null?e:!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!r)return;let o=!1;const l=r.connect({name:t}),i=m(n,a=>{const d=a.filter(([h,c])=>c[0]!==j).map(([h,c])=>`${h}:${c.map(String).join(".")}`).join(", ");if(d)if(o)o=!1;else{const h=Object.assign({},y(n));delete h[j],l.send({type:d,updatedAt:new Date().toLocaleString()},h)}}),u=l.subscribe(a=>{var d,h,c,p,E,w;if(a.type==="ACTION"&&a.payload)try{Object.assign(n,JSON.parse(a.payload))}catch(f){console.error(`please dispatch a serializable value that JSON.parse() and proxy() support
`,f)}if(a.type==="DISPATCH"&&a.state){if(((d=a.payload)==null?void 0:d.type)==="JUMP_TO_ACTION"||((h=a.payload)==null?void 0:h.type)==="JUMP_TO_STATE"){o=!0;const f=JSON.parse(a.state);Object.assign(n,f)}n[j]=a}else if(a.type==="DISPATCH"&&((c=a.payload)==null?void 0:c.type)==="COMMIT")l.init(y(n));else if(a.type==="DISPATCH"&&((p=a.payload)==null?void 0:p.type)==="IMPORT_STATE"){const f=(E=a.payload.nextLiftedState)==null?void 0:E.actionsById,K=((w=a.payload.nextLiftedState)==null?void 0:w.computedStates)||[];o=!0,K.forEach(({state:X},D)=>{const $=f[D]||"No action found";Object.assign(n,X),D===0?l.init(y(n)):l.send($,y(n))})}});return l.init(y(n)),()=>{i(),u==null||u()}}const g=new WeakMap,O=new WeakMap,C=(n,s)=>{const e=g.get(n);e&&(e[0].forEach(t=>{const{d:r}=t;n!==r&&C(r)}),++e[2],s&&e[3].add(s))},H=(n,s)=>{const e=g.get(n);return e!=null&&e[2]?(e[3].add(s),!0):!1},T=n=>{const s=g.get(n);s&&(--s[2],s[2]||(s[3].forEach(e=>e()),s[3].clear()),s[0].forEach(e=>{const{d:t}=e;n!==t&&T(t)}))},M=n=>{const{s,d:e}=n;let t=O.get(e);t||(t=[new Set],O.set(n.d,t)),t[0].add(n);let r=g.get(s);if(!r){const o=new Set,l=m(s,i=>{o.forEach(u=>{const{d:a,c:d,n:h,i:c}=u;s===a&&i.every(p=>p[1].length===1&&c.includes(p[1][0]))||u.p||(C(s,d),h?T(s):u.p=Promise.resolve().then(()=>{delete u.p,T(s)}))})},!0);r=[o,l,0,new Set],g.set(s,r)}r[0].add(n)},P=n=>{const{s,d:e}=n,t=O.get(e);t==null||t[0].delete(n),(t==null?void 0:t[0].size)===0&&O.delete(e);const r=g.get(s);if(r){const[o,l]=r;o.delete(n),o.size||(l(),g.delete(s))}},_=n=>{const s=O.get(n);return s?Array.from(s[0]):[]},B=A("unstable_deriveSubscriptions",{add:M,remove:P,list:_});function N(n,s){const e=(s==null?void 0:s.proxy)||v({}),t=!!(s!=null&&s.sync),r=Object.keys(n);return r.forEach(o=>{if(Object.getOwnPropertyDescriptor(e,o))throw new Error("object property already defined");const l=n[o];let i=null;const u=()=>{if(i&&(Array.from(i).map(([c])=>H(c,u)).some(c=>c)||Array.from(i).every(([c,p])=>x(c)===p.v)))return;const a=new Map,d=l(c=>(a.set(c,{v:x(c)}),c)),h=()=>{a.forEach((c,p)=>{var E;const w=(E=i==null?void 0:i.get(p))==null?void 0:E.s;if(w)c.s=w;else{const f={s:p,d:e,k:o,c:u,n:t,i:r};M(f),c.s=f}}),i==null||i.forEach((c,p)=>{!a.has(p)&&c.s&&P(c.s)}),i=a};d instanceof Promise?d.finally(h):h(),e[o]=d};u()}),e}function z(n,s){const e=s!=null&&s.delete?new Set:null;_(n).forEach(t=>{const{k:r}=t;(!(s!=null&&s.keys)||s.keys.includes(r))&&(P(t),e&&e.add(r))}),e&&e.forEach(t=>{delete n[t]})}function W(n,s,e=n){console.warn("addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201");const t={};return Object.keys(s).forEach(r=>{t[r]=o=>s[r](o(n))}),N(t,{proxy:e})}function R(n,s){Object.keys(s).forEach(t=>{if(Object.getOwnPropertyDescriptor(n,t))throw new Error("object property already defined");const r=s[t],{get:o,set:l}=typeof r=="function"?{get:r}:r,i={};i.get=()=>o(y(e)),l&&(i.set=u=>l(e,u)),Object.defineProperty(n,t,i)});const e=v(n);return e}function U(n,s=!1){const e=v({value:n,history:k({wip:n,snapshots:[],index:-1}),canUndo:()=>e.history.index>0,undo:()=>{e.canUndo()&&(e.value=e.history.wip=e.history.snapshots[--e.history.index],e.history.snapshots[e.history.index]=y(e).value)},canRedo:()=>e.history.index<e.history.snapshots.length-1,redo:()=>{e.canRedo()&&(e.value=e.history.wip=e.history.snapshots[++e.history.index],e.history.snapshots[e.history.index]=y(e).value)},saveHistory:()=>{e.history.snapshots.splice(e.history.index+1),e.history.snapshots.push(y(e).value),++e.history.index},subscribe:()=>m(e,t=>{t.every(r=>r[1][0]==="value"&&(r[0]!=="set"||r[2]!==e.history.wip))&&e.saveHistory()})});return e.saveHistory(),s||e.subscribe(),e}function L(n){const s=v({data:Array.from(new Set(n)),has(e){return this.data.indexOf(e)!==-1},add(e){let t=!1;return typeof e=="object"&&e!==null&&(t=this.data.indexOf(v(e))!==-1),this.data.indexOf(e)===-1&&!t&&this.data.push(e),this},delete(e){const t=this.data.indexOf(e);return t===-1?!1:(this.data.splice(t,1),!0)},clear(){this.data.splice(0)},get size(){return this.data.length},forEach(e){this.data.forEach(t=>{e(t,t,this)})},get[Symbol.toStringTag](){return"Set"},toJSON(){return{}},[Symbol.iterator](){return this.data[Symbol.iterator]()},values(){return this.data.values()},keys(){return this.data.values()},entries(){return new Set(this.data).entries()}});return Object.defineProperties(s,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(s),s}function V(n){const s=v({data:Array.from(n||[]),has(e){return this.data.some(t=>t[0]===e)},set(e,t){const r=this.data.find(o=>o[0]===e);return r?r[1]=t:this.data.push([e,t]),this},get(e){var t;return(t=this.data.find(r=>r[0]===e))==null?void 0:t[1]},delete(e){const t=this.data.findIndex(r=>r[0]===e);return t===-1?!1:(this.data.splice(t,1),!0)},clear(){this.data.splice(0)},get size(){return this.data.length},toJSON(){return{}},forEach(e){this.data.forEach(t=>{e(t[1],t[0],this)})},keys(){return this.data.map(e=>e[0]).values()},values(){return this.data.map(e=>e[1]).values()},entries(){return new Map(this.data).entries()},get[Symbol.toStringTag](){return"Map"},[Symbol.iterator](){return this.entries()}});return Object.defineProperties(s,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(s),s}}}});

@@ -1,1 +0,1 @@

System.register(["proxy-compare"],function(K){"use strict";var k,O;return{setters:[function(g){k=g.getUntracked,O=g.markToTrack}],execute:function(){K({getHandler:B,getVersion:V,proxy:M,ref:N,snapshot:z,subscribe:q});const g=Symbol(),a=Symbol(),j=Symbol(),R=Symbol(),d=Symbol(),v=Symbol(),w=new WeakSet;function N(t){return w.add(t),t}const P=t=>typeof t=="object"&&t!==null,U=t=>P(t)&&!w.has(t)&&(Array.isArray(t)||!(Symbol.iterator in t))&&!(t instanceof WeakMap)&&!(t instanceof WeakSet)&&!(t instanceof Error)&&!(t instanceof Number)&&!(t instanceof Date)&&!(t instanceof String)&&!(t instanceof RegExp)&&!(t instanceof ArrayBuffer),x=new WeakMap;let A=1;const E=new WeakMap;function M(t={}){if(!P(t))throw new Error("object required");const h=x.get(t);if(h)return h;let l=A;const y=new Set,f=(n,e=++A)=>{l!==e&&(l=e,y.forEach(r=>r(n,e)))},u=new Map,m=n=>{let e=u.get(n);return e||(e=(r,o)=>{const c=[...r];c[1]=[n,...c[1]],f(c,o)},u.set(n,e)),e},T=n=>{const e=u.get(n);return u.delete(n),e},I=(n,e)=>{const r=E.get(e);if((r==null?void 0:r[0])===l)return r[1];const o=Array.isArray(n)?[]:Object.create(Object.getPrototypeOf(n));return O(o,!0),E.set(e,[l,o]),Reflect.ownKeys(n).forEach(c=>{const i=Reflect.get(n,c,e);if(w.has(i))O(i,!1),o[c]=i;else if(i instanceof Promise)if(d in i)o[c]=i[d];else{const b=i[v]||i;Object.defineProperty(o,c,{get(){if(d in i)return i[d];throw b}})}else i!=null&&i[a]?o[c]=i[j]:o[c]=i}),Object.freeze(o),o},W=Array.isArray(t)?[]:Object.create(Object.getPrototypeOf(t)),D={get(n,e,r){return e===g?l:e===a?y:e===j?I(n,r):e===R?D:Reflect.get(n,e,r)},deleteProperty(n,e){const r=Reflect.get(n,e),o=r==null?void 0:r[a];o&&o.delete(T(e));const c=Reflect.deleteProperty(n,e);return c&&f(["delete",[e],r]),c},is:Object.is,canProxy:U,set(n,e,r,o){var c;const i=Reflect.has(n,e),b=Reflect.get(n,e,o);if(i&&this.is(b,r))return!0;const H=b==null?void 0:b[a];H&&H.delete(T(e)),P(r)&&(r=k(r)||r);let s;return(c=Object.getOwnPropertyDescriptor(n,e))!=null&&c.set?s=r:r instanceof Promise?s=r.then(p=>(s[d]=p,f(["resolve",[e],p]),p)).catch(p=>{s[v]=p,f(["reject",[e],p])}):r!=null&&r[a]?(s=r,s[a].add(m(e))):this.canProxy(r)?(s=M(r),s[a].add(m(e))):s=r,Reflect.set(n,e,s,o),f(["set",[e],r,b]),!0}},S=new Proxy(W,D);return x.set(t,S),Reflect.ownKeys(t).forEach(n=>{const e=Object.getOwnPropertyDescriptor(t,n);e.get||e.set?Object.defineProperty(W,n,e):S[n]=t[n]}),S}function V(t){return P(t)?t[g]:void 0}function q(t,h,l){let y;const f=[],u=m=>{if(f.push(m),l){h(f.splice(0));return}y||(y=Promise.resolve().then(()=>{y=void 0,h(f.splice(0))}))};return t[a].add(u),()=>{t[a].delete(u)}}function z(t){return t[j]}function B(t){return t[R]}}}});
System.register(["proxy-compare"],function(K){"use strict";var k,P;return{setters:[function(g){k=g.getUntracked,P=g.markToTrack}],execute:function(){K({getHandler:B,getVersion:V,proxy:T,ref:N,snapshot:z,subscribe:q});const g=Symbol(),a=Symbol(),j=Symbol(),R=Symbol(),d=Symbol(),v=Symbol(),w=new WeakSet;function N(t){return w.add(t),t}const m=t=>typeof t=="object"&&t!==null,U=t=>m(t)&&!w.has(t)&&(Array.isArray(t)||!(Symbol.iterator in t))&&!(t instanceof WeakMap)&&!(t instanceof WeakSet)&&!(t instanceof Error)&&!(t instanceof Number)&&!(t instanceof Date)&&!(t instanceof String)&&!(t instanceof RegExp)&&!(t instanceof ArrayBuffer),x=new WeakMap;let A=1;const E=new WeakMap;function T(t={}){if(!m(t))throw new Error("object required");const h=x.get(t);if(h)return h;let l=A;const y=new Set,f=(n,e=++A)=>{l!==e&&(l=e,y.forEach(r=>r(n,e)))},u=new Map,O=n=>{let e=u.get(n);return e||(e=(r,o)=>{const c=[...r];c[1]=[n,...c[1]],f(c,o)},u.set(n,e)),e},M=n=>{const e=u.get(n);return u.delete(n),e},I=(n,e)=>{const r=E.get(e);if((r==null?void 0:r[0])===l)return r[1];const o=Array.isArray(n)?[]:Object.create(Object.getPrototypeOf(n));return P(o,!0),E.set(e,[l,o]),Reflect.ownKeys(n).forEach(c=>{const i=Reflect.get(n,c,e);if(w.has(i))P(i,!1),o[c]=i;else if(i instanceof Promise)if(d in i)o[c]=i[d];else{const b=i[v]||i;Object.defineProperty(o,c,{get(){if(d in i)return i[d];throw b}})}else i!=null&&i[a]?o[c]=i[j]:o[c]=i}),Object.freeze(o),o},W=Array.isArray(t)?[]:Object.create(Object.getPrototypeOf(t)),D={get(n,e,r){return e===g?l:e===a?y:e===j?I(n,r):e===R?D:Reflect.get(n,e,r)},deleteProperty(n,e){const r=Reflect.get(n,e),o=r==null?void 0:r[a];o&&o.delete(M(e));const c=Reflect.deleteProperty(n,e);return c&&f(["delete",[e],r]),c},is:Object.is,canProxy:U,set(n,e,r,o){var c;const i=Reflect.has(n,e),b=Reflect.get(n,e,o);if(i&&this.is(b,r))return!0;const H=b==null?void 0:b[a];H&&H.delete(M(e)),m(r)&&(r=k(r)||r);let s;return(c=Object.getOwnPropertyDescriptor(n,e))!=null&&c.set?s=r:r instanceof Promise?s=r.then(p=>(s[d]=p,f(["resolve",[e],p]),p)).catch(p=>{s[v]=p,f(["reject",[e],p])}):r!=null&&r[a]?(s=r,s[a].add(O(e))):this.canProxy(r)?(s=T(r),s[a].add(O(e))):s=r,Reflect.set(n,e,s,o),f(["set",[e],r,b]),!0}},S=new Proxy(W,D);return x.set(t,S),Reflect.ownKeys(t).forEach(n=>{const e=Object.getOwnPropertyDescriptor(t,n);e.get||e.set?Object.defineProperty(W,n,e):S[n]=t[n]}),S}function V(t){return m(t)?t[g]:void 0}function q(t,h,l){let y;const f=[],u=O=>{if(f.push(O),l){h(f.splice(0));return}y||(y=Promise.resolve().then(()=>{y=void 0,h(f.splice(0))}))};return t[a].add(u),()=>{t[a].delete(u)}}function z(t){return t[j]}function B(t){return t[R]}}}});

@@ -1,11 +0,9 @@

declare type AsRef = {
$$valtioRef: true;
};
import { INTERNAL_AsRef } from './vanilla';
declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;
};
declare type Options = {
interface Options {
sync?: boolean;
};
}
/**

@@ -12,0 +10,0 @@ * useSnapshot

declare type DeriveGet = <T extends object>(proxyObject: T) => T;
declare type Subscription = {
interface Subscription {
s: object;

@@ -10,3 +10,3 @@ d: object;

p?: Promise<void>;
};
}
export declare const unstable_deriveSubscriptions: {

@@ -13,0 +13,0 @@ add: (subscription: Subscription) => void;

@@ -1,5 +0,5 @@

declare type Options = {
interface Options {
enabled?: boolean;
name?: string;
};
}
export declare function devtools<T extends object>(proxyObject: T, options?: Options): (() => void) | undefined;

@@ -6,0 +6,0 @@ /**

@@ -1,6 +0,4 @@

declare type AsRef = {
$$valtioRef: true;
};
import { INTERNAL_AsRef } from '../vanilla';
declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;

@@ -7,0 +5,0 @@ };

declare type Cleanup = () => void;
declare type WatchGet = <T extends object>(proxyObject: T) => T;
declare type WatchCallback = (get: WatchGet) => Cleanup | void | undefined;
declare type WatchOptions = {
interface WatchOptions {
sync?: boolean;
};
}
/**

@@ -8,0 +8,0 @@ * watch

@@ -1,5 +0,9 @@

declare type AsRef = {
/**
* This not a public API.
* It can be changed without notice.
*/
export interface INTERNAL_AsRef {
$$valtioRef: true;
};
export declare function ref<T extends object>(o: T): T & AsRef;
}
export declare function ref<T extends object>(o: T): T & INTERNAL_AsRef;
declare type Path = (string | symbol)[];

@@ -28,3 +32,3 @@ declare type Op = [

declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;

@@ -31,0 +35,0 @@ };

@@ -1,11 +0,9 @@

declare type AsRef = {
$$valtioRef: true;
};
import { INTERNAL_AsRef } from './vanilla';
declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;
};
declare type Options = {
interface Options {
sync?: boolean;
};
}
/**

@@ -12,0 +10,0 @@ * useSnapshot

declare type DeriveGet = <T extends object>(proxyObject: T) => T;
declare type Subscription = {
interface Subscription {
s: object;

@@ -10,3 +10,3 @@ d: object;

p?: Promise<void>;
};
}
export declare const unstable_deriveSubscriptions: {

@@ -13,0 +13,0 @@ add: (subscription: Subscription) => void;

@@ -1,5 +0,5 @@

declare type Options = {
interface Options {
enabled?: boolean;
name?: string;
};
}
export declare function devtools<T extends object>(proxyObject: T, options?: Options): (() => void) | undefined;

@@ -6,0 +6,0 @@ /**

@@ -1,6 +0,4 @@

declare type AsRef = {
$$valtioRef: true;
};
import { INTERNAL_AsRef } from '../vanilla';
declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;

@@ -7,0 +5,0 @@ };

declare type Cleanup = () => void;
declare type WatchGet = <T extends object>(proxyObject: T) => T;
declare type WatchCallback = (get: WatchGet) => Cleanup | void | undefined;
declare type WatchOptions = {
interface WatchOptions {
sync?: boolean;
};
}
/**

@@ -8,0 +8,0 @@ * watch

@@ -1,5 +0,9 @@

declare type AsRef = {
/**
* This not a public API.
* It can be changed without notice.
*/
export interface INTERNAL_AsRef {
$$valtioRef: true;
};
export declare function ref<T extends object>(o: T): T & AsRef;
}
export declare function ref<T extends object>(o: T): T & INTERNAL_AsRef;
declare type Path = (string | symbol)[];

@@ -28,3 +32,3 @@ declare type Op = [

declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;

@@ -31,0 +35,0 @@ };

@@ -88,3 +88,3 @@ (function (global, factory) {

if (typeof options === 'string') {
console.warn('[Deprecated] Please use option object instead of name string');
console.warn('string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400');
options = {

@@ -455,3 +455,3 @@ name: options

console.warn('addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive.');
console.warn('addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201');
var derivedFns = {};

@@ -458,0 +458,0 @@ Object.keys(computedFns_FAKE).forEach(function (key) {

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("valtio/vanilla")):"function"==typeof define&&define.amd?define(["exports","valtio/vanilla"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).valtioUtils={},t.valtioVanilla)}(this,(function(t,e){"use strict";var n;var r=Symbol();var i=new WeakMap,a=new WeakMap,o=function t(e,n){var r=i.get(e);r&&(r[0].forEach((function(n){var r=n.d;e!==r&&t(r)})),++r[2],n&&r[3].add(n))},s=function t(e){var n=i.get(e);n&&(--n[2],n[2]||(n[3].forEach((function(t){return t()})),n[3].clear()),n[0].forEach((function(n){var r=n.d;e!==r&&t(r)})))},u=function(t){var n=t.s,r=t.d,u=a.get(r);u||(u=[new Set],a.set(t.d,u)),u[0].add(t);var c=i.get(n);if(!c){var f=new Set,d=e.subscribe(n,(function(t){f.forEach((function(e){var r=e.d,i=e.c,a=e.n,u=e.i;n===r&&t.every((function(t){return 1===t[1].length&&u.includes(t[1][0])}))||e.p||(o(n,i),a?s(n):e.p=Promise.resolve().then((function(){delete e.p,s(n)})))}))}),!0);c=[f,d,0,new Set],i.set(n,c)}c[0].add(t)},c=function(t){var e=t.s,n=t.d,r=a.get(n);null==r||r[0].delete(t),0===(null==r?void 0:r[0].size)&&a.delete(n);var o=i.get(e);if(o){var s=o[0],u=o[1];s.delete(t),s.size||(u(),i.delete(e))}},f=function(t){var e=a.get(t);return e?Array.from(e[0]):[]},d={add:u,remove:c,list:f};function l(t,n){var r=(null==n?void 0:n.proxy)||e.proxy({}),a=!(null==n||!n.sync),o=Object.keys(t);return o.forEach((function(n){if(Object.getOwnPropertyDescriptor(r,n))throw new Error("object property already defined");var s=t[n],f=null;!function t(){if(f){if(Array.from(f).map((function(e){var n,r,a,o=e[0];return n=o,r=t,!(null==(a=i.get(n))||!a[2]||(a[3].add(r),0))})).some((function(t){return t})))return;if(Array.from(f).every((function(t){var n=t[0],r=t[1];return e.getVersion(n)===r.v})))return}var d=new Map,l=s((function(t){return d.set(t,{v:e.getVersion(t)}),t})),p=function(){var e;d.forEach((function(e,i){var s,c,d=null==(s=f)||null==(c=s.get(i))?void 0:c.s;if(d)e.s=d;else{var l={s:i,d:r,k:n,c:t,n:a,i:o};u(l),e.s=l}})),null==(e=f)||e.forEach((function(t,e){!d.has(e)&&t.s&&c(t.s)})),f=d};l instanceof Promise?l.finally(p):p(),r[n]=l}()})),r}function p(t,e){for(var n in e){(a=e[n]).configurable=a.enumerable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,n,a)}if(Object.getOwnPropertySymbols)for(var r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++){var a,o=r[i];(a=e[o]).configurable=a.enumerable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,o,a)}return t}t.addComputed=function(t,e,n){void 0===n&&(n=t),console.warn("addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive.");var r={};return Object.keys(e).forEach((function(n){r[n]=function(r){return e[n](r(t))}})),l(r,{proxy:n})},t.derive=l,t.devtools=function(t,n){"string"==typeof n&&(console.warn("[Deprecated] Please use option object instead of name string"),n={name:n});var i,a=n||{},o=a.enabled,s=a.name,u=void 0===s?"":s;try{i=null!=o&&o&&window.__REDUX_DEVTOOLS_EXTENSION__}catch(t){}if(i){var c=!1,f=i.connect({name:u}),d=e.subscribe(t,(function(n){var i=n.filter((function(t){return t[0],t[1][0]!==r})).map((function(t){return t[0]+":"+t[1].map(String).join(".")})).join(", ");if(i)if(c)c=!1;else{var a=Object.assign({},e.snapshot(t));delete a[r],f.send({type:i,updatedAt:(new Date).toLocaleString()},a)}})),l=f.subscribe((function(n){var i,a;if("ACTION"===n.type&&n.payload)try{Object.assign(t,JSON.parse(n.payload))}catch(t){console.error("please dispatch a serializable value that JSON.parse() and proxy() support\n",t)}if("DISPATCH"===n.type&&n.state){var o,s;if("JUMP_TO_ACTION"===(null==(o=n.payload)?void 0:o.type)||"JUMP_TO_STATE"===(null==(s=n.payload)?void 0:s.type)){c=!0;var u=JSON.parse(n.state);Object.assign(t,u)}t[r]=n}else if("DISPATCH"===n.type&&"COMMIT"===(null==(i=n.payload)?void 0:i.type))f.init(e.snapshot(t));else if("DISPATCH"===n.type&&"IMPORT_STATE"===(null==(a=n.payload)?void 0:a.type)){var d,l,p=null==(d=n.payload.nextLiftedState)?void 0:d.actionsById,h=(null==(l=n.payload.nextLiftedState)?void 0:l.computedStates)||[];c=!0,h.forEach((function(n,r){var i=n.state,a=p[r]||"No action found";Object.assign(t,i),0===r?f.init(e.snapshot(t)):f.send(a,e.snapshot(t))}))}}));return f.init(e.snapshot(t)),function(){d(),null==l||l()}}},t.proxyMap=function(t){var n,r,i,a=e.proxy((r={data:Array.from(t||[]),has:function(t){return this.data.some((function(e){return e[0]===t}))},set:function(t,e){var n=this.data.find((function(e){return e[0]===t}));return n?n[1]=e:this.data.push([t,e]),this},get:function(t){var e;return null==(e=this.data.find((function(e){return e[0]===t})))?void 0:e[1]},delete:function(t){var e=this.data.findIndex((function(e){return e[0]===t}));return-1!==e&&(this.data.splice(e,1),!0)},clear:function(){this.data.splice(0)},get size(){return this.data.length},toJSON:function(){return{}},forEach:function(t){var e=this;this.data.forEach((function(n){t(n[1],n[0],e)}))},keys:function(){return this.data.map((function(t){return t[0]})).values()},values:function(){return this.data.map((function(t){return t[1]})).values()},entries:function(){return new Map(this.data).entries()}},(i={})[n=Symbol.toStringTag]=i[n]||{},i[n].get=function(){return"Map"},r[Symbol.iterator]=function(){return this.entries()},p(r,i),r));return Object.defineProperties(a,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(a),a},t.proxySet=function(t){var n,r,i,a=e.proxy((r={data:Array.from(new Set(t)),has:function(t){return-1!==this.data.indexOf(t)},add:function(t){var n=!1;return"object"==typeof t&&null!==t&&(n=-1!==this.data.indexOf(e.proxy(t))),-1!==this.data.indexOf(t)||n||this.data.push(t),this},delete:function(t){var e=this.data.indexOf(t);return-1!==e&&(this.data.splice(e,1),!0)},clear:function(){this.data.splice(0)},get size(){return this.data.length},forEach:function(t){var e=this;this.data.forEach((function(n){t(n,n,e)}))}},(i={})[n=Symbol.toStringTag]=i[n]||{},i[n].get=function(){return"Set"},r.toJSON=function(){return{}},r[Symbol.iterator]=function(){return this.data[Symbol.iterator]()},r.values=function(){return this.data.values()},r.keys=function(){return this.data.values()},r.entries=function(){return new Set(this.data).entries()},p(r,i),r));return Object.defineProperties(a,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(a),a},t.proxyWithComputed=function(t,n){Object.keys(n).forEach((function(i){if(Object.getOwnPropertyDescriptor(t,i))throw new Error("object property already defined");var a=n[i],o="function"==typeof a?{get:a}:a,s=o.get,u=o.set,c={get:function(){return s(e.snapshot(r))}};u&&(c.set=function(t){return u(r,t)}),Object.defineProperty(t,i,c)}));var r=e.proxy(t);return r},t.proxyWithHistory=function(t,n){void 0===n&&(n=!1);var r=e.proxy({value:t,history:e.ref({wip:t,snapshots:[],index:-1}),canUndo:function(){return r.history.index>0},undo:function(){r.canUndo()&&(r.value=r.history.wip=r.history.snapshots[--r.history.index],r.history.snapshots[r.history.index]=e.snapshot(r).value)},canRedo:function(){return r.history.index<r.history.snapshots.length-1},redo:function(){r.canRedo()&&(r.value=r.history.wip=r.history.snapshots[++r.history.index],r.history.snapshots[r.history.index]=e.snapshot(r).value)},saveHistory:function(){r.history.snapshots.splice(r.history.index+1),r.history.snapshots.push(e.snapshot(r).value),++r.history.index},subscribe:function(){return e.subscribe(r,(function(t){t.every((function(t){return"value"===t[1][0]&&("set"!==t[0]||t[2]!==r.history.wip)}))&&r.saveHistory()}))}});return r.saveHistory(),n||r.subscribe(),r},t.subscribeKey=function(t,n,r,i){return e.subscribe(t,(function(e){e.some((function(t){return t[1][0]===n}))&&r(t[n])}),i)},t.underive=function(t,e){var n=null!=e&&e.delete?new Set:null;f(t).forEach((function(t){var r=t.k;null!=e&&e.keys&&!e.keys.includes(r)||(c(t),n&&n.add(r))})),n&&n.forEach((function(e){delete t[e]}))},t.unstable_deriveSubscriptions=d,t.watch=function(t,r){var i=!0,a=new Set,o=new Map,s=function(){i&&(i=!1,a.forEach((function(t){return t()})),a.clear(),o.forEach((function(t){return t()})),o.clear())};return n&&n.add(s),function s(){if(i){a.forEach((function(t){return t()})),a.clear();var u=new Set,c=n;n=a;try{var f=t((function(t){return u.add(t),t}));f&&a.add(f)}finally{n=c}o.forEach((function(t,e){u.has(e)?u.delete(e):(o.delete(e),t())})),u.forEach((function(t){var n=e.subscribe(t,s,null==r?void 0:r.sync);o.set(t,n)}))}}(),s},Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("valtio/vanilla")):"function"==typeof define&&define.amd?define(["exports","valtio/vanilla"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).valtioUtils={},t.valtioVanilla)}(this,(function(t,e){"use strict";var n;var r=Symbol();var i=new WeakMap,a=new WeakMap,o=function t(e,n){var r=i.get(e);r&&(r[0].forEach((function(n){var r=n.d;e!==r&&t(r)})),++r[2],n&&r[3].add(n))},s=function t(e){var n=i.get(e);n&&(--n[2],n[2]||(n[3].forEach((function(t){return t()})),n[3].clear()),n[0].forEach((function(n){var r=n.d;e!==r&&t(r)})))},u=function(t){var n=t.s,r=t.d,u=a.get(r);u||(u=[new Set],a.set(t.d,u)),u[0].add(t);var c=i.get(n);if(!c){var f=new Set,l=e.subscribe(n,(function(t){f.forEach((function(e){var r=e.d,i=e.c,a=e.n,u=e.i;n===r&&t.every((function(t){return 1===t[1].length&&u.includes(t[1][0])}))||e.p||(o(n,i),a?s(n):e.p=Promise.resolve().then((function(){delete e.p,s(n)})))}))}),!0);c=[f,l,0,new Set],i.set(n,c)}c[0].add(t)},c=function(t){var e=t.s,n=t.d,r=a.get(n);null==r||r[0].delete(t),0===(null==r?void 0:r[0].size)&&a.delete(n);var o=i.get(e);if(o){var s=o[0],u=o[1];s.delete(t),s.size||(u(),i.delete(e))}},f=function(t){var e=a.get(t);return e?Array.from(e[0]):[]},l={add:u,remove:c,list:f};function d(t,n){var r=(null==n?void 0:n.proxy)||e.proxy({}),a=!(null==n||!n.sync),o=Object.keys(t);return o.forEach((function(n){if(Object.getOwnPropertyDescriptor(r,n))throw new Error("object property already defined");var s=t[n],f=null;!function t(){if(f){if(Array.from(f).map((function(e){var n,r,a,o=e[0];return n=o,r=t,!(null==(a=i.get(n))||!a[2]||(a[3].add(r),0))})).some((function(t){return t})))return;if(Array.from(f).every((function(t){var n=t[0],r=t[1];return e.getVersion(n)===r.v})))return}var l=new Map,d=s((function(t){return l.set(t,{v:e.getVersion(t)}),t})),p=function(){var e;l.forEach((function(e,i){var s,c,l=null==(s=f)||null==(c=s.get(i))?void 0:c.s;if(l)e.s=l;else{var d={s:i,d:r,k:n,c:t,n:a,i:o};u(d),e.s=d}})),null==(e=f)||e.forEach((function(t,e){!l.has(e)&&t.s&&c(t.s)})),f=l};d instanceof Promise?d.finally(p):p(),r[n]=d}()})),r}function p(t,e){for(var n in e){(a=e[n]).configurable=a.enumerable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,n,a)}if(Object.getOwnPropertySymbols)for(var r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++){var a,o=r[i];(a=e[o]).configurable=a.enumerable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,o,a)}return t}t.addComputed=function(t,e,n){void 0===n&&(n=t),console.warn("addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201");var r={};return Object.keys(e).forEach((function(n){r[n]=function(r){return e[n](r(t))}})),d(r,{proxy:n})},t.derive=d,t.devtools=function(t,n){"string"==typeof n&&(console.warn("string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400"),n={name:n});var i,a=n||{},o=a.enabled,s=a.name,u=void 0===s?"":s;try{i=null!=o&&o&&window.__REDUX_DEVTOOLS_EXTENSION__}catch(t){}if(i){var c=!1,f=i.connect({name:u}),l=e.subscribe(t,(function(n){var i=n.filter((function(t){return t[0],t[1][0]!==r})).map((function(t){return t[0]+":"+t[1].map(String).join(".")})).join(", ");if(i)if(c)c=!1;else{var a=Object.assign({},e.snapshot(t));delete a[r],f.send({type:i,updatedAt:(new Date).toLocaleString()},a)}})),d=f.subscribe((function(n){var i,a;if("ACTION"===n.type&&n.payload)try{Object.assign(t,JSON.parse(n.payload))}catch(t){console.error("please dispatch a serializable value that JSON.parse() and proxy() support\n",t)}if("DISPATCH"===n.type&&n.state){var o,s;if("JUMP_TO_ACTION"===(null==(o=n.payload)?void 0:o.type)||"JUMP_TO_STATE"===(null==(s=n.payload)?void 0:s.type)){c=!0;var u=JSON.parse(n.state);Object.assign(t,u)}t[r]=n}else if("DISPATCH"===n.type&&"COMMIT"===(null==(i=n.payload)?void 0:i.type))f.init(e.snapshot(t));else if("DISPATCH"===n.type&&"IMPORT_STATE"===(null==(a=n.payload)?void 0:a.type)){var l,d,p=null==(l=n.payload.nextLiftedState)?void 0:l.actionsById,h=(null==(d=n.payload.nextLiftedState)?void 0:d.computedStates)||[];c=!0,h.forEach((function(n,r){var i=n.state,a=p[r]||"No action found";Object.assign(t,i),0===r?f.init(e.snapshot(t)):f.send(a,e.snapshot(t))}))}}));return f.init(e.snapshot(t)),function(){l(),null==d||d()}}},t.proxyMap=function(t){var n,r,i,a=e.proxy((r={data:Array.from(t||[]),has:function(t){return this.data.some((function(e){return e[0]===t}))},set:function(t,e){var n=this.data.find((function(e){return e[0]===t}));return n?n[1]=e:this.data.push([t,e]),this},get:function(t){var e;return null==(e=this.data.find((function(e){return e[0]===t})))?void 0:e[1]},delete:function(t){var e=this.data.findIndex((function(e){return e[0]===t}));return-1!==e&&(this.data.splice(e,1),!0)},clear:function(){this.data.splice(0)},get size(){return this.data.length},toJSON:function(){return{}},forEach:function(t){var e=this;this.data.forEach((function(n){t(n[1],n[0],e)}))},keys:function(){return this.data.map((function(t){return t[0]})).values()},values:function(){return this.data.map((function(t){return t[1]})).values()},entries:function(){return new Map(this.data).entries()}},(i={})[n=Symbol.toStringTag]=i[n]||{},i[n].get=function(){return"Map"},r[Symbol.iterator]=function(){return this.entries()},p(r,i),r));return Object.defineProperties(a,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(a),a},t.proxySet=function(t){var n,r,i,a=e.proxy((r={data:Array.from(new Set(t)),has:function(t){return-1!==this.data.indexOf(t)},add:function(t){var n=!1;return"object"==typeof t&&null!==t&&(n=-1!==this.data.indexOf(e.proxy(t))),-1!==this.data.indexOf(t)||n||this.data.push(t),this},delete:function(t){var e=this.data.indexOf(t);return-1!==e&&(this.data.splice(e,1),!0)},clear:function(){this.data.splice(0)},get size(){return this.data.length},forEach:function(t){var e=this;this.data.forEach((function(n){t(n,n,e)}))}},(i={})[n=Symbol.toStringTag]=i[n]||{},i[n].get=function(){return"Set"},r.toJSON=function(){return{}},r[Symbol.iterator]=function(){return this.data[Symbol.iterator]()},r.values=function(){return this.data.values()},r.keys=function(){return this.data.values()},r.entries=function(){return new Set(this.data).entries()},p(r,i),r));return Object.defineProperties(a,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(a),a},t.proxyWithComputed=function(t,n){Object.keys(n).forEach((function(i){if(Object.getOwnPropertyDescriptor(t,i))throw new Error("object property already defined");var a=n[i],o="function"==typeof a?{get:a}:a,s=o.get,u=o.set,c={get:function(){return s(e.snapshot(r))}};u&&(c.set=function(t){return u(r,t)}),Object.defineProperty(t,i,c)}));var r=e.proxy(t);return r},t.proxyWithHistory=function(t,n){void 0===n&&(n=!1);var r=e.proxy({value:t,history:e.ref({wip:t,snapshots:[],index:-1}),canUndo:function(){return r.history.index>0},undo:function(){r.canUndo()&&(r.value=r.history.wip=r.history.snapshots[--r.history.index],r.history.snapshots[r.history.index]=e.snapshot(r).value)},canRedo:function(){return r.history.index<r.history.snapshots.length-1},redo:function(){r.canRedo()&&(r.value=r.history.wip=r.history.snapshots[++r.history.index],r.history.snapshots[r.history.index]=e.snapshot(r).value)},saveHistory:function(){r.history.snapshots.splice(r.history.index+1),r.history.snapshots.push(e.snapshot(r).value),++r.history.index},subscribe:function(){return e.subscribe(r,(function(t){t.every((function(t){return"value"===t[1][0]&&("set"!==t[0]||t[2]!==r.history.wip)}))&&r.saveHistory()}))}});return r.saveHistory(),n||r.subscribe(),r},t.subscribeKey=function(t,n,r,i){return e.subscribe(t,(function(e){e.some((function(t){return t[1][0]===n}))&&r(t[n])}),i)},t.underive=function(t,e){var n=null!=e&&e.delete?new Set:null;f(t).forEach((function(t){var r=t.k;null!=e&&e.keys&&!e.keys.includes(r)||(c(t),n&&n.add(r))})),n&&n.forEach((function(e){delete t[e]}))},t.unstable_deriveSubscriptions=l,t.watch=function(t,r){var i=!0,a=new Set,o=new Map,s=function(){i&&(i=!1,a.forEach((function(t){return t()})),a.clear(),o.forEach((function(t){return t()})),o.clear())};return n&&n.add(s),function s(){if(i){a.forEach((function(t){return t()})),a.clear();var u=new Set,c=n;n=a;try{var f=t((function(t){return u.add(t),t}));f&&a.add(f)}finally{n=c}o.forEach((function(t,e){u.has(e)?u.delete(e):(o.delete(e),t())})),u.forEach((function(t){var n=e.subscribe(t,s,null==r?void 0:r.sync);o.set(t,n)}))}}(),s},Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -88,3 +88,3 @@ 'use strict';

if (typeof options === 'string') {
console.warn('[Deprecated] Please use option object instead of name string');
console.warn('string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400');
options = {

@@ -455,3 +455,3 @@ name: options

console.warn('addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive.');
console.warn('addComputed is deprecated. Please consider using `derive` or `proxyWithComputed` instead. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201');
var derivedFns = {};

@@ -458,0 +458,0 @@ Object.keys(computedFns_FAKE).forEach(function (key) {

declare type DeriveGet = <T extends object>(proxyObject: T) => T;
declare type Subscription = {
interface Subscription {
s: object;

@@ -10,3 +10,3 @@ d: object;

p?: Promise<void>;
};
}
export declare const unstable_deriveSubscriptions: {

@@ -13,0 +13,0 @@ add: (subscription: Subscription) => void;

@@ -1,5 +0,5 @@

declare type Options = {
interface Options {
enabled?: boolean;
name?: string;
};
}
export declare function devtools<T extends object>(proxyObject: T, options?: Options): (() => void) | undefined;

@@ -6,0 +6,0 @@ /**

@@ -1,6 +0,4 @@

declare type AsRef = {
$$valtioRef: true;
};
import type { INTERNAL_AsRef } from '../vanilla';
declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;

@@ -7,0 +5,0 @@ };

declare type Cleanup = () => void;
declare type WatchGet = <T extends object>(proxyObject: T) => T;
declare type WatchCallback = (get: WatchGet) => Cleanup | void | undefined;
declare type WatchOptions = {
interface WatchOptions {
sync?: boolean;
};
}
/**

@@ -8,0 +8,0 @@ * watch

@@ -1,5 +0,9 @@

declare type AsRef = {
/**
* This not a public API.
* It can be changed without notice.
*/
export interface INTERNAL_AsRef {
$$valtioRef: true;
};
export declare function ref<T extends object>(o: T): T & AsRef;
}
export declare function ref<T extends object>(o: T): T & INTERNAL_AsRef;
declare type Path = (string | symbol)[];

@@ -11,3 +15,3 @@ declare type Op = [op: 'set', path: Path, value: unknown, prevValue: unknown] | [op: 'delete', path: Path, prevValue: unknown] | [op: 'resolve', path: Path, value: unknown] | [op: 'reject', path: Path, error: unknown];

declare type AnyFunction = (...args: any[]) => any;
declare type Snapshot<T> = T extends AnyFunction ? T : T extends AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
declare type Snapshot<T> = T extends AnyFunction ? T : T extends INTERNAL_AsRef ? T : T extends Promise<infer V> ? Snapshot<V> : {
readonly [K in keyof T]: Snapshot<T[K]>;

@@ -14,0 +18,0 @@ };

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