Comparing version 1.9.0 to 1.10.0
@@ -1,2 +0,2 @@ | ||
export * from './vanilla'; | ||
export * from './react'; | ||
export * from 'valtio/vanilla'; | ||
export * from 'valtio/react'; |
@@ -1,2 +0,2 @@ | ||
import type { INTERNAL_Snapshot as Snapshot } from './vanilla'; | ||
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
type Options = { | ||
@@ -3,0 +3,0 @@ sync?: boolean; |
@@ -1,2 +0,2 @@ | ||
export * from './vanilla/utils'; | ||
export * from './react/utils'; | ||
export * from 'valtio/vanilla/utils'; | ||
export * from 'valtio/react/utils'; |
@@ -134,3 +134,3 @@ import { markToTrack, getUntracked } from 'proxy-compare'; | ||
const prevValue = Reflect.get(target, prop, receiver); | ||
if (hasPrevValue && objectIs(prevValue, value)) { | ||
if (hasPrevValue && (objectIs(prevValue, value) || proxyCache.has(value) && objectIs(prevValue, proxyCache.get(value)))) { | ||
return true; | ||
@@ -137,0 +137,0 @@ } |
@@ -6,5 +6,5 @@ export { subscribeKey } from './utils/subscribeKey'; | ||
export { addComputed_DEPRECATED as addComputed } from './utils/addComputed'; | ||
export { proxyWithComputed } from './utils/proxyWithComputed'; | ||
export { proxyWithComputed_DEPRECATED as proxyWithComputed } from './utils/proxyWithComputed'; | ||
export { proxyWithHistory } from './utils/proxyWithHistory'; | ||
export { proxySet } from './utils/proxySet'; | ||
export { proxyMap } from './utils/proxyMap'; |
@@ -106,3 +106,3 @@ import { subscribe, snapshot, proxy, getVersion, ref } from 'valtio/vanilla'; | ||
type: action, | ||
updatedAt: new Date().toLocaleString() | ||
updatedAt: (/* @__PURE__ */ new Date()).toLocaleString() | ||
}, | ||
@@ -361,5 +361,7 @@ snapWithoutDevtools | ||
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. https://github.com/pmndrs/valtio/pull/201" | ||
); | ||
if (process.env.NODE_ENV !== "production") { | ||
console.warn( | ||
"addComputed is deprecated. Please consider using `derive`. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201" | ||
); | ||
} | ||
const derivedFns = {}; | ||
@@ -372,3 +374,8 @@ Object.keys(computedFns_FAKE).forEach((key) => { | ||
function proxyWithComputed(initialObject, computedFns) { | ||
function proxyWithComputed_DEPRECATED(initialObject, computedFns) { | ||
if (process.env.NODE_ENV !== "production") { | ||
console.warn( | ||
'proxyWithComputed is deprecated. Please follow "Computed Properties" guide in docs.' | ||
); | ||
} | ||
Object.keys(computedFns).forEach((key) => { | ||
@@ -588,2 +595,2 @@ if (Object.getOwnPropertyDescriptor(initialObject, key)) { | ||
export { addComputed_DEPRECATED as addComputed, derive, devtools, proxyMap, proxySet, proxyWithComputed, proxyWithHistory, subscribeKey, underive, unstable_deriveSubscriptions, watch }; | ||
export { addComputed_DEPRECATED as addComputed, derive, devtools, proxyMap, proxySet, proxyWithComputed_DEPRECATED as proxyWithComputed, proxyWithHistory, subscribeKey, underive, unstable_deriveSubscriptions, watch }; |
@@ -1,27 +0,8 @@ | ||
import type { INTERNAL_Snapshot as Snapshot } from '../../vanilla'; | ||
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
/** | ||
* proxyWithComputed | ||
* proxyWithComputed (DEPRECATED) | ||
* | ||
* This is to create a proxy with initial object and additional object, | ||
* which specifies getters for computed values with dependency tracking. | ||
* It also accepts optional setters for computed values. | ||
* | ||
* [Notes] | ||
* This comes with a cost and overlaps with useSnapshot. | ||
* Do not try to optimize too early. It can worsen the performance. | ||
* Measurement and comparison will be very important. | ||
* | ||
* @example | ||
* import { proxyWithComputed } from 'valtio/utils' | ||
* const state = proxyWithComputed({ | ||
* count: 1, | ||
* }, { | ||
* doubled: snap => snap.count * 2, // getter only | ||
* tripled: { | ||
* get: snap => snap.count * 3, | ||
* set: (state, newValue) => { state.count = newValue / 3 } | ||
* }, // with optional setter | ||
* }) | ||
* @deprecated Please follow "Computed Properties" guide in docs. | ||
*/ | ||
export declare function proxyWithComputed<T extends object, U extends object>(initialObject: T, computedFns: { | ||
export declare function proxyWithComputed_DEPRECATED<T extends object, U extends object>(initialObject: T, computedFns: { | ||
[K in keyof U]: ((snap: Snapshot<T>) => U[K]) | { | ||
@@ -28,0 +9,0 @@ get: (snap: Snapshot<T>) => U[K]; |
@@ -1,2 +0,2 @@ | ||
import type { INTERNAL_Snapshot as Snapshot } from '../../vanilla'; | ||
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
type SnapshotOrUndefined<T> = Snapshot<T> | undefined; | ||
@@ -3,0 +3,0 @@ type Snapshots<T> = Snapshot<T>[]; |
@@ -1,2 +0,2 @@ | ||
export * from './vanilla'; | ||
export * from './react'; | ||
export * from 'valtio/vanilla'; | ||
export * from 'valtio/react'; |
@@ -29,3 +29,3 @@ 'use strict'; | ||
var references = _ref.references; | ||
if (process.env.NODE_ENV !== "production") { | ||
if (process.env.NODE_ENV !== 'production') { | ||
console.warn('[DEPRECATED] Use useProxy hook instead.'); | ||
@@ -32,0 +32,0 @@ } |
@@ -65,3 +65,3 @@ 'use strict'; | ||
function provideValtioMacro() { | ||
if (process.env.NODE_ENV !== "production") { | ||
if (process.env.NODE_ENV !== 'production') { | ||
console.warn('[DEPRECATED] Use useProxy hook instead.'); | ||
@@ -68,0 +68,0 @@ } |
{ | ||
"name": "valtio", | ||
"private": false, | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "💊 Valtio makes proxy-state simple for React and Vanilla", | ||
@@ -6,0 +6,0 @@ "main": "./index.js", |
@@ -1,2 +0,2 @@ | ||
import type { INTERNAL_Snapshot as Snapshot } from './vanilla'; | ||
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
type Options = { | ||
@@ -3,0 +3,0 @@ sync?: boolean; |
@@ -43,3 +43,3 @@ 'use strict'; | ||
}); | ||
if (process.env.NODE_ENV !== "production") { | ||
if (process.env.NODE_ENV !== 'production') { | ||
useAffectedDebugValue(currSnapshot, currAffected); | ||
@@ -46,0 +46,0 @@ } |
@@ -275,3 +275,3 @@ <img src="logo.svg" alt="valtio"> | ||
it's confusing for beginners. | ||
We have a convenient util to improve developer experience. | ||
We have a convenient util to improve developer experience. useProxy returns shallow proxy state and its snapshot, meaning you can only mutate on root level. | ||
@@ -284,7 +284,9 @@ ```js | ||
const Component = () => { | ||
const combined = useProxy(state) // combined with proxy state and its snapshot | ||
// useProxy returns a special proxy that can be used both in render and callbacks | ||
// The special proxy has to be used directly in a function scope. You can't destructure it outside the scope. | ||
const $state = useProxy(state) | ||
return ( | ||
<div> | ||
{combined.count} | ||
<button onClick={() => ++combined.count}>+1</button> | ||
{$state.count} | ||
<button onClick={() => ++$state.count}>+1</button> | ||
</div> | ||
@@ -323,57 +325,2 @@ ) | ||
#### `proxyWithComputed` util | ||
You can define own computed properties within a proxy. | ||
By combining with a memoization library such as | ||
[proxy-memoize](https://github.com/dai-shi/proxy-memoize), | ||
optimizing function calls is possible. | ||
Be careful not to overuse `proxy-memoize` | ||
because `proxy-memoize` and `useSnapshot` do similar optimization | ||
and double optimization may lead to less performance. | ||
```js | ||
import { memoize } from 'proxy-memoize' | ||
import { proxyWithComputed } from 'valtio/utils' | ||
const state = proxyWithComputed( | ||
{ | ||
count: 1, | ||
}, | ||
{ | ||
doubled: memoize((snap) => snap.count * 2), | ||
} | ||
) | ||
// Computed values accept custom setters too: | ||
const state2 = proxyWithComputed( | ||
{ | ||
firstName: 'Alec', | ||
lastName: 'Baldwin', | ||
}, | ||
{ | ||
fullName: { | ||
get: memoize((snap) => snap.firstName + ' ' + snap.lastName), | ||
set: (state, newValue) => { | ||
;[state.firstName, state.lastName] = newValue.split(' ') | ||
}, | ||
}, | ||
} | ||
) | ||
// if you want a computed value to derive from another computed, you must declare the dependency first: | ||
const state = proxyWithComputed( | ||
{ | ||
count: 1, | ||
}, | ||
{ | ||
doubled: memoize((snap) => snap.count * 2), | ||
quadrupled: memoize((snap) => snap.doubled * 2), | ||
} | ||
) | ||
``` | ||
The last use case fails to infer types in TypeScript | ||
[#192](https://github.com/pmndrs/valtio/issues/192). | ||
#### `proxyWithHistory` util | ||
@@ -380,0 +327,0 @@ |
@@ -1,1 +0,1 @@ | ||
System.register(["@babel/helper-module-imports","@babel/types","babel-plugin-macros"],function(h){"use strict";var i,n,l,c;return{setters:[function(e){i=e.addNamed},function(e){n=e},function(e){l=e.createMacro,c=e.MacroError}],execute:function(){var y=h("default",l(({references:g})=>{var s;(s=g.useProxy)==null||s.forEach(a=>{var u,d,m,f,v,p;const x=i(a,"useSnapshot","valtio"),t=(d=(u=a.parentPath)==null?void 0:u.get("arguments.0"))==null?void 0:d.node;if(!n.isIdentifier(t))throw new c("no proxy object");const b=n.identifier(`valtio_macro_snap_${t.name}`);(f=(m=a.parentPath)==null?void 0:m.parentPath)==null||f.replaceWith(n.variableDeclaration("const",[n.variableDeclarator(b,n.callExpression(x,[t]))]));let r=0;(p=(v=a.parentPath)==null?void 0:v.getFunctionParent())==null||p.traverse({Identifier(o){r===0&&o.node!==t&&o.node.name===t.name&&(o.node.name=b.name)},Function:{enter(){++r},exit(){--r}}})})},{configName:"valtio"}))}}}); | ||
System.register(["@babel/helper-module-imports","@babel/types","babel-plugin-macros"],function(h){"use strict";var i,n,l,c;return{setters:[function(e){i=e.addNamed},function(e){n=e},function(e){l=e.createMacro,c=e.MacroError}],execute:function(){var P=h("default",l(({references:g})=>{var s;(s=g.useProxy)==null||s.forEach(a=>{var u,d,m,p,v,f;const y=i(a,"useSnapshot","valtio"),r=(d=(u=a.parentPath)==null?void 0:u.get("arguments.0"))==null?void 0:d.node;if(!n.isIdentifier(r))throw new c("no proxy object");const b=n.identifier(`valtio_macro_snap_${r.name}`);(p=(m=a.parentPath)==null?void 0:m.parentPath)==null||p.replaceWith(n.variableDeclaration("const",[n.variableDeclarator(b,n.callExpression(y,[r]))]));let t=0;(f=(v=a.parentPath)==null?void 0:v.getFunctionParent())==null||f.traverse({Identifier(o){t===0&&o.node!==r&&o.node.name===r.name&&(o.node.name=b.name)},Function:{enter(){++t},exit(){--t}}})})},{configName:"valtio"}))}}}); |
@@ -1,1 +0,1 @@ | ||
System.register(["@babel/helper-module-imports","@babel/types","aslemammad-vite-plugin-macro","babel-plugin-macros"],function(o){"use strict";var l,t,n,u;return{setters:[function(e){l=e},function(e){t=e},function(e){n=e},function(e){u=e}],execute:function(){o("provideValtioMacro",s);const{defineMacro:e,defineMacroProvider:b,createMacroPlugin:h}="default"in n?n.default:n,M=o("valtioMacro",e("useProxy").withSignature("<T extends object>(proxyObject: T): void").withHandler(g=>{var d,m,v,f;const{path:r,args:x}=g,P=l.addNamed(r,"useSnapshot","valtio"),a=(d=x[0])==null?void 0:d.node;if(!t.isIdentifier(a))throw new u.MacroError("no proxy object");const p=t.identifier(`valtio_macro_snap_${a.name}`);(m=r.parentPath)==null||m.replaceWith(t.variableDeclaration("const",[t.variableDeclarator(p,t.callExpression(P,[a]))]));let i=0;(f=(v=r.parentPath)==null?void 0:v.getFunctionParent())==null||f.traverse({Identifier(c){i===0&&c.node!==a&&c.node.name===a.name&&(c.node.name=p.name)},Function:{enter(){++i},exit(){--i}}})}));function s(){return b({id:"valtio/macro",exports:{"valtio/macro":{macros:[M]}}})}const y=o("default",h({}).use(s()))}}}); | ||
System.register(["@babel/helper-module-imports","@babel/types","aslemammad-vite-plugin-macro","babel-plugin-macros"],function(o){"use strict";var l,t,a,u;return{setters:[function(e){l=e},function(e){t=e},function(e){a=e},function(e){u=e}],execute:function(){o("provideValtioMacro",s);const{defineMacro:e,defineMacroProvider:b,createMacroPlugin:h}="default"in a?a.default:a,M=o("valtioMacro",e("useProxy").withSignature("<T extends object>(proxyObject: T): void").withHandler(g=>{var d,m,v,f;const{path:r,args:x}=g,P=l.addNamed(r,"useSnapshot","valtio"),n=(d=x[0])==null?void 0:d.node;if(!t.isIdentifier(n))throw new u.MacroError("no proxy object");const p=t.identifier(`valtio_macro_snap_${n.name}`);(m=r.parentPath)==null||m.replaceWith(t.variableDeclaration("const",[t.variableDeclarator(p,t.callExpression(P,[n]))]));let i=0;(f=(v=r.parentPath)==null?void 0:v.getFunctionParent())==null||f.traverse({Identifier(c){i===0&&c.node!==n&&c.node.name===n.name&&(c.node.name=p.name)},Function:{enter(){++i},exit(){--i}}})}));function s(){return b({id:"valtio/macro",exports:{"valtio/macro":{macros:[M]}}})}const y=o("default",h({}).use(s()))}}}); |
@@ -150,3 +150,3 @@ System.register(['proxy-compare'], (function (exports) { | ||
const prevValue = Reflect.get(target, prop, receiver); | ||
if (hasPrevValue && objectIs(prevValue, value)) { | ||
if (hasPrevValue && (objectIs(prevValue, value) || proxyCache.has(value) && objectIs(prevValue, proxyCache.get(value)))) { | ||
return true; | ||
@@ -153,0 +153,0 @@ } |
@@ -1,1 +0,1 @@ | ||
System.register(["proxy-compare"],function(x){"use strict";var A,z;return{setters:[function(w){A=w.markToTrack,z=w.getUntracked}],execute:function(){x({getVersion:N,proxy:D,ref:_,snapshot:F,subscribe:U});const w=c=>typeof c=="object"&&c!==null,y=new WeakMap,P=new WeakSet,M=(c=Object.is,i=(t,j)=>new Proxy(t,j),O=t=>w(t)&&!P.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),k=t=>{switch(t.status){case"fulfilled":return t.value;case"rejected":throw t.reason;default:throw t}},l=new WeakMap,g=(t,j,d=k)=>{const a=l.get(t);if((a==null?void 0:a[0])===j)return a[1];const s=Array.isArray(t)?[]:Object.create(Object.getPrototypeOf(t));return A(s,!0),l.set(t,[j,s]),Reflect.ownKeys(t).forEach(h=>{const f=Reflect.get(t,h);P.has(f)?(A(f,!1),s[h]=f):f instanceof Promise?Object.defineProperty(s,h,{get(){return d(f)}}):y.has(f)?s[h]=F(f,d):s[h]=f}),Object.freeze(s)},v=new WeakMap,u=[1,1],S=t=>{if(!w(t))throw new Error("object required");const j=v.get(t);if(j)return j;let d=u[0];const a=new Set,s=(n,e=++u[0])=>{d!==e&&(d=e,a.forEach(r=>r(n,e)))};let h=u[1];const f=(n=++u[1])=>(h!==n&&!a.size&&(h=n,p.forEach(([e])=>{const r=e[1](n);r>d&&(d=r)})),d),T=n=>(e,r)=>{const o=[...e];o[1]=[n,...o[1]],s(o,r)},p=new Map,q=(n,e)=>{if(a.size){const r=e[3](T(n));p.set(n,[e,r])}else p.set(n,[e])},V=n=>{var e;const r=p.get(n);r&&(p.delete(n),(e=r[1])==null||e.call(r))},B=n=>(a.add(n),a.size===1&&p.forEach(([e,r],o)=>{const R=e[3](T(o));p.set(o,[e,R])}),()=>{a.delete(n),a.size===0&&p.forEach(([e,r],o)=>{r&&(r(),p.set(o,[e]))})}),W=Array.isArray(t)?[]:Object.create(Object.getPrototypeOf(t)),E=i(W,{deleteProperty(n,e){const r=Reflect.get(n,e);V(e);const o=Reflect.deleteProperty(n,e);return o&&s(["delete",[e],r]),o},set(n,e,r,o){var R;const G=Reflect.has(n,e),K=Reflect.get(n,e,o);if(G&&c(K,r))return!0;V(e),w(r)&&(r=z(r)||r);let m=r;if(!((R=Object.getOwnPropertyDescriptor(n,e))!=null&&R.set))if(r instanceof Promise)r.then(b=>{r.status="fulfilled",r.value=b,s(["resolve",[e],b])}).catch(b=>{r.status="rejected",r.reason=b,s(["reject",[e],b])});else{!y.has(r)&&O(r)&&(m=D(r));const b=!P.has(m)&&y.get(m);b&&q(e,b)}return Reflect.set(n,e,m,o),s(["set",[e],r,K]),!0}});v.set(t,E);const C=[W,f,g,B];return y.set(E,C),Reflect.ownKeys(t).forEach(n=>{const e=Object.getOwnPropertyDescriptor(t,n);e.get||e.set?Object.defineProperty(W,n,e):E[n]=t[n]}),E})=>[S,y,P,c,i,O,k,l,g,v,u],[L]=M();function D(c={}){return L(c)}function N(c){const i=y.get(c);return i==null?void 0:i[1]()}function U(c,i,O){const k=y.get(c);let l;const g=[],v=k[3];let u=!1;const S=v(t=>{if(g.push(t),O){i(g.splice(0));return}l||(l=Promise.resolve().then(()=>{l=void 0,u&&i(g.splice(0))}))});return u=!0,()=>{u=!1,S()}}function F(c,i){const O=y.get(c),[k,l,g]=O;return g(k,l(),i)}function _(c){return P.add(c),c}const H=x("unstable_buildProxyFunction",M)}}}); | ||
System.register(["proxy-compare"],function(m){"use strict";var S,M;return{setters:[function(O){S=O.markToTrack,M=O.getUntracked}],execute:function(){m({getVersion:U,proxy:F,ref:q,snapshot:T,subscribe:_});const O=c=>typeof c=="object"&&c!==null,g=new WeakMap,P=new WeakSet,D=(c=Object.is,i=(t,j)=>new Proxy(t,j),k=t=>O(t)&&!P.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),v=t=>{switch(t.status){case"fulfilled":return t.value;case"rejected":throw t.reason;default:throw t}},l=new WeakMap,p=(t,j,h=v)=>{const a=l.get(t);if((a==null?void 0:a[0])===j)return a[1];const s=Array.isArray(t)?[]:Object.create(Object.getPrototypeOf(t));return S(s,!0),l.set(t,[j,s]),Reflect.ownKeys(t).forEach(d=>{const f=Reflect.get(t,d);P.has(f)?(S(f,!1),s[d]=f):f instanceof Promise?Object.defineProperty(s,d,{get(){return h(f)}}):g.has(f)?s[d]=T(f,h):s[d]=f}),Object.freeze(s)},w=new WeakMap,u=[1,1],x=t=>{if(!O(t))throw new Error("object required");const j=w.get(t);if(j)return j;let h=u[0];const a=new Set,s=(n,e=++u[0])=>{h!==e&&(h=e,a.forEach(r=>r(n,e)))};let d=u[1];const f=(n=++u[1])=>(d!==n&&!a.size&&(d=n,y.forEach(([e])=>{const r=e[1](n);r>h&&(h=r)})),h),V=n=>(e,r)=>{const o=[...e];o[1]=[n,...o[1]],s(o,r)},y=new Map,B=(n,e)=>{if(a.size){const r=e[3](V(n));y.set(n,[e,r])}else y.set(n,[e])},K=n=>{var e;const r=y.get(n);r&&(y.delete(n),(e=r[1])==null||e.call(r))},L=n=>(a.add(n),a.size===1&&y.forEach(([e,r],o)=>{const R=e[3](V(o));y.set(o,[e,R])}),()=>{a.delete(n),a.size===0&&y.forEach(([e,r],o)=>{r&&(r(),y.set(o,[e]))})}),W=Array.isArray(t)?[]:Object.create(Object.getPrototypeOf(t)),E=i(W,{deleteProperty(n,e){const r=Reflect.get(n,e);K(e);const o=Reflect.deleteProperty(n,e);return o&&s(["delete",[e],r]),o},set(n,e,r,o){var R;const G=Reflect.has(n,e),z=Reflect.get(n,e,o);if(G&&(c(z,r)||w.has(r)&&c(z,w.get(r))))return!0;K(e),O(r)&&(r=M(r)||r);let A=r;if(!((R=Object.getOwnPropertyDescriptor(n,e))!=null&&R.set))if(r instanceof Promise)r.then(b=>{r.status="fulfilled",r.value=b,s(["resolve",[e],b])}).catch(b=>{r.status="rejected",r.reason=b,s(["reject",[e],b])});else{!g.has(r)&&k(r)&&(A=F(r));const b=!P.has(A)&&g.get(A);b&&B(e,b)}return Reflect.set(n,e,A,o),s(["set",[e],r,z]),!0}});w.set(t,E);const C=[W,f,p,L];return g.set(E,C),Reflect.ownKeys(t).forEach(n=>{const e=Object.getOwnPropertyDescriptor(t,n);e.get||e.set?Object.defineProperty(W,n,e):E[n]=t[n]}),E})=>[x,g,P,c,i,k,v,l,p,w,u],[N]=D();function F(c={}){return N(c)}function U(c){const i=g.get(c);return i==null?void 0:i[1]()}function _(c,i,k){const v=g.get(c);let l;const p=[],w=v[3];let u=!1;const x=w(t=>{if(p.push(t),k){i(p.splice(0));return}l||(l=Promise.resolve().then(()=>{l=void 0,u&&i(p.splice(0))}))});return u=!0,()=>{u=!1,x()}}function T(c,i){const k=g.get(c),[v,l,p]=k;return p(v,l(),i)}function q(c){return P.add(c),c}const H=m("unstable_buildProxyFunction",D)}}}); |
@@ -20,3 +20,3 @@ System.register(['valtio/vanilla'], (function (exports) { | ||
proxySet: proxySet, | ||
proxyWithComputed: proxyWithComputed, | ||
proxyWithComputed: proxyWithComputed_DEPRECATED, | ||
proxyWithHistory: proxyWithHistory, | ||
@@ -131,3 +131,3 @@ subscribeKey: subscribeKey, | ||
type: action, | ||
updatedAt: new Date().toLocaleString() | ||
updatedAt: (/* @__PURE__ */ new Date()).toLocaleString() | ||
}, | ||
@@ -386,5 +386,7 @@ snapWithoutDevtools | ||
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. https://github.com/pmndrs/valtio/pull/201" | ||
); | ||
{ | ||
console.warn( | ||
"addComputed is deprecated. Please consider using `derive`. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201" | ||
); | ||
} | ||
const derivedFns = {}; | ||
@@ -397,3 +399,8 @@ Object.keys(computedFns_FAKE).forEach((key) => { | ||
function proxyWithComputed(initialObject, computedFns) { | ||
function proxyWithComputed_DEPRECATED(initialObject, computedFns) { | ||
{ | ||
console.warn( | ||
'proxyWithComputed is deprecated. Please follow "Computed Properties" guide in docs.' | ||
); | ||
} | ||
Object.keys(computedFns).forEach((key) => { | ||
@@ -400,0 +407,0 @@ if (Object.getOwnPropertyDescriptor(initialObject, key)) { |
@@ -1,2 +0,2 @@ | ||
System.register(["valtio/vanilla"],function(M){"use strict";var S,y,b,x,k;return{setters:[function(v){S=v.subscribe,y=v.snapshot,b=v.proxy,x=v.getVersion,k=v.ref}],execute:function(){M({addComputed:R,derive:D,devtools:H,proxyMap:X,proxySet:V,proxyWithComputed:U,proxyWithHistory:K,subscribeKey:v,underive:W,watch:J});function v(s,t,e,n){let r=s[t];return S(s,()=>{const o=s[t];Object.is(r,o)||e(r=o)},n)}let O;function J(s,t){let e=!0;const n=new Set,r=new Map,o=()=>{e&&(e=!1,n.forEach(i=>i()),n.clear(),r.forEach(i=>i()),r.clear())},l=()=>{if(!e)return;n.forEach(a=>a()),n.clear();const i=new Set,u=O;O=n;try{const a=s(d=>(i.add(d),d));a&&n.add(a)}finally{O=u}r.forEach((a,d)=>{i.has(d)?i.delete(d):(r.delete(d),a())}),i.forEach(a=>{const d=S(a,l,t==null?void 0:t.sync);r.set(a,d)})};return O&&O.add(o),l(),o}const j=Symbol();function H(s,t){typeof t=="string"&&(console.warn("string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400"),t={name:t});const{enabled:e,name:n=""}=t||{};let r;try{r=(e!=null?e:!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!r)return;let o=!1;const l=r.connect({name:n}),i=S(s,a=>{const d=a.filter(([p,c])=>c[0]!==j).map(([p,c])=>`${p}:${c.map(String).join(".")}`).join(", ");if(d)if(o)o=!1;else{const p=Object.assign({},y(s));delete p[j],l.send({type:d,updatedAt:new Date().toLocaleString()},p)}}),u=l.subscribe(a=>{var d,p,c,h,w,E;if(a.type==="ACTION"&&a.payload)try{Object.assign(s,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"||((p=a.payload)==null?void 0:p.type)==="JUMP_TO_STATE"){o=!0;const f=JSON.parse(a.state);Object.assign(s,f)}s[j]=a}else if(a.type==="DISPATCH"&&((c=a.payload)==null?void 0:c.type)==="COMMIT")l.init(y(s));else if(a.type==="DISPATCH"&&((h=a.payload)==null?void 0:h.type)==="IMPORT_STATE"){const f=(w=a.payload.nextLiftedState)==null?void 0:w.actionsById,$=((E=a.payload.nextLiftedState)==null?void 0:E.computedStates)||[];o=!0,$.forEach(({state:B},I)=>{const F=f[I]||"No action found";Object.assign(s,B),I===0?l.init(y(s)):l.send(F,y(s))})}});return l.init(y(s)),()=>{i(),u==null||u()}}const g=new WeakMap,m=new WeakMap,C=(s,t)=>{const e=g.get(s);e&&(e[0].forEach(n=>{const{d:r}=n;s!==r&&C(r)}),++e[2],t&&e[3].add(t))},z=(s,t)=>{const e=g.get(s);return e!=null&&e[2]?(e[3].add(t),!0):!1},T=s=>{const t=g.get(s);t&&(--t[2],t[2]||(t[3].forEach(e=>e()),t[3].clear()),t[0].forEach(e=>{const{d:n}=e;s!==n&&T(n)}))},_=s=>{const{s:t,d:e}=s;let n=m.get(e);n||(n=[new Set],m.set(s.d,n)),n[0].add(s);let r=g.get(t);if(!r){const o=new Set,l=S(t,i=>{o.forEach(u=>{const{d:a,c:d,n:p,i:c}=u;t===a&&i.every(h=>h[1].length===1&&c.includes(h[1][0]))||u.p||(C(t,d),p?T(t):u.p=Promise.resolve().then(()=>{delete u.p,T(t)}))})},!0);r=[o,l,0,new Set],g.set(t,r)}r[0].add(s)},A=s=>{const{s:t,d:e}=s,n=m.get(e);n==null||n[0].delete(s),(n==null?void 0:n[0].size)===0&&m.delete(e);const r=g.get(t);if(r){const[o,l]=r;o.delete(s),o.size||(l(),g.delete(t))}},N=s=>{const t=m.get(s);return t?Array.from(t[0]):[]},q=M("unstable_deriveSubscriptions",{add:_,remove:A,list:N});function D(s,t){const e=(t==null?void 0:t.proxy)||b({}),n=!!(t!=null&&t.sync),r=Object.keys(s);return r.forEach(o=>{if(Object.getOwnPropertyDescriptor(e,o))throw new Error("object property already defined");const l=s[o];let i=null;const u=()=>{if(i&&(Array.from(i).map(([c])=>z(c,u)).some(c=>c)||Array.from(i).every(([c,h])=>x(c)===h.v)))return;const a=new Map,d=l(c=>(a.set(c,{v:x(c)}),c)),p=()=>{a.forEach((c,h)=>{var w;const E=(w=i==null?void 0:i.get(h))==null?void 0:w.s;if(E)c.s=E;else{const f={s:h,d:e,k:o,c:u,n,i:r};_(f),c.s=f}}),i==null||i.forEach((c,h)=>{!a.has(h)&&c.s&&A(c.s)}),i=a};d instanceof Promise?d.finally(p):p(),e[o]=d};u()}),e}function W(s,t){const e=t!=null&&t.delete?new Set:null;N(s).forEach(n=>{const{k:r}=n;(!(t!=null&&t.keys)||t.keys.includes(r))&&(A(n),e&&e.add(r))}),e&&e.forEach(n=>{delete s[n]})}function R(s,t,e=s){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 n={};return Object.keys(t).forEach(r=>{n[r]=o=>t[r](o(s))}),D(n,{proxy:e})}function U(s,t){Object.keys(t).forEach(n=>{if(Object.getOwnPropertyDescriptor(s,n))throw new Error("object property already defined");const r=t[n],{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(s,n,i)});const e=b(s);return e}const L=s=>typeof s=="object"&&s!==null,P=s=>{if(!L(s))return s;const t=Array.isArray(s)?[]:Object.create(Object.getPrototypeOf(s));return Reflect.ownKeys(s).forEach(e=>{t[e]=P(s[e])}),t};function K(s,t=!1){const e=b({value:s,history:k({wip:void 0,snapshots:[],index:-1}),canUndo:()=>e.history.index>0,undo:()=>{e.canUndo()&&(e.value=e.history.wip=P(e.history.snapshots[--e.history.index]))},canRedo:()=>e.history.index<e.history.snapshots.length-1,redo:()=>{e.canRedo()&&(e.value=e.history.wip=P(e.history.snapshots[++e.history.index]))},saveHistory:()=>{e.history.snapshots.splice(e.history.index+1),e.history.snapshots.push(y(e).value),++e.history.index},subscribe:()=>S(e,n=>{n.every(r=>r[1][0]==="value"&&(r[0]!=="set"||r[2]!==e.history.wip))&&e.saveHistory()})});return e.saveHistory(),t||e.subscribe(),e}function V(s){const t=b({data:Array.from(new Set(s)),has(e){return this.data.indexOf(e)!==-1},add(e){let n=!1;return typeof e=="object"&&e!==null&&(n=this.data.indexOf(b(e))!==-1),this.data.indexOf(e)===-1&&!n&&this.data.push(e),this},delete(e){const n=this.data.indexOf(e);return n===-1?!1:(this.data.splice(n,1),!0)},clear(){this.data.splice(0)},get size(){return this.data.length},forEach(e){this.data.forEach(n=>{e(n,n,this)})},get[Symbol.toStringTag](){return"Set"},toJSON(){return new Set(this.data)},[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(t,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(t),t}function X(s){const t=b({data:Array.from(s||[]),has(e){return this.data.some(n=>n[0]===e)},set(e,n){const r=this.data.find(o=>o[0]===e);return r?r[1]=n:this.data.push([e,n]),this},get(e){var n;return(n=this.data.find(r=>r[0]===e))==null?void 0:n[1]},delete(e){const n=this.data.findIndex(r=>r[0]===e);return n===-1?!1:(this.data.splice(n,1),!0)},clear(){this.data.splice(0)},get size(){return this.data.length},toJSON(){return new Map(this.data)},forEach(e){this.data.forEach(n=>{e(n[1],n[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(t,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(t),t}}}}); | ||
System.register(["valtio/vanilla"],function(M){"use strict";var O,y,b,x,_;return{setters:[function(v){O=v.subscribe,y=v.snapshot,b=v.proxy,x=v.getVersion,_=v.ref}],execute:function(){M({addComputed:W,derive:N,devtools:H,proxyMap:X,proxySet:V,proxyWithComputed:U,proxyWithHistory:K,subscribeKey:v,underive:R,watch:J});function v(s,t,e,n){let r=s[t];return O(s,()=>{const o=s[t];Object.is(r,o)||e(r=o)},n)}let g;function J(s,t){let e=!0;const n=new Set,r=new Map,o=()=>{e&&(e=!1,n.forEach(i=>i()),n.clear(),r.forEach(i=>i()),r.clear())},l=()=>{if(!e)return;n.forEach(a=>a()),n.clear();const i=new Set,u=g;g=n;try{const a=s(d=>(i.add(d),d));a&&n.add(a)}finally{g=u}r.forEach((a,d)=>{i.has(d)?i.delete(d):(r.delete(d),a())}),i.forEach(a=>{const d=O(a,l,t==null?void 0:t.sync);r.set(a,d)})};return g&&g.add(o),l(),o}const j=Symbol();function H(s,t){typeof t=="string"&&(console.warn("string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400"),t={name:t});const{enabled:e,name:n=""}=t||{};let r;try{r=(e!=null?e:!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!r)return;let o=!1;const l=r.connect({name:n}),i=O(s,a=>{const d=a.filter(([p,c])=>c[0]!==j).map(([p,c])=>`${p}:${c.map(String).join(".")}`).join(", ");if(d)if(o)o=!1;else{const p=Object.assign({},y(s));delete p[j],l.send({type:d,updatedAt:new Date().toLocaleString()},p)}}),u=l.subscribe(a=>{var d,p,c,h,m,w;if(a.type==="ACTION"&&a.payload)try{Object.assign(s,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"||((p=a.payload)==null?void 0:p.type)==="JUMP_TO_STATE"){o=!0;const f=JSON.parse(a.state);Object.assign(s,f)}s[j]=a}else if(a.type==="DISPATCH"&&((c=a.payload)==null?void 0:c.type)==="COMMIT")l.init(y(s));else if(a.type==="DISPATCH"&&((h=a.payload)==null?void 0:h.type)==="IMPORT_STATE"){const f=(m=a.payload.nextLiftedState)==null?void 0:m.actionsById,$=((w=a.payload.nextLiftedState)==null?void 0:w.computedStates)||[];o=!0,$.forEach(({state:B},I)=>{const q=f[I]||"No action found";Object.assign(s,B),I===0?l.init(y(s)):l.send(q,y(s))})}});return l.init(y(s)),()=>{i(),u==null||u()}}const S=new WeakMap,E=new WeakMap,D=(s,t)=>{const e=S.get(s);e&&(e[0].forEach(n=>{const{d:r}=n;s!==r&&D(r)}),++e[2],t&&e[3].add(t))},z=(s,t)=>{const e=S.get(s);return e!=null&&e[2]?(e[3].add(t),!0):!1},T=s=>{const t=S.get(s);t&&(--t[2],t[2]||(t[3].forEach(e=>e()),t[3].clear()),t[0].forEach(e=>{const{d:n}=e;s!==n&&T(n)}))},k=s=>{const{s:t,d:e}=s;let n=E.get(e);n||(n=[new Set],E.set(s.d,n)),n[0].add(s);let r=S.get(t);if(!r){const o=new Set,l=O(t,i=>{o.forEach(u=>{const{d:a,c:d,n:p,i:c}=u;t===a&&i.every(h=>h[1].length===1&&c.includes(h[1][0]))||u.p||(D(t,d),p?T(t):u.p=Promise.resolve().then(()=>{delete u.p,T(t)}))})},!0);r=[o,l,0,new Set],S.set(t,r)}r[0].add(s)},A=s=>{const{s:t,d:e}=s,n=E.get(e);n==null||n[0].delete(s),(n==null?void 0:n[0].size)===0&&E.delete(e);const r=S.get(t);if(r){const[o,l]=r;o.delete(s),o.size||(l(),S.delete(t))}},C=s=>{const t=E.get(s);return t?Array.from(t[0]):[]},F=M("unstable_deriveSubscriptions",{add:k,remove:A,list:C});function N(s,t){const e=(t==null?void 0:t.proxy)||b({}),n=!!(t!=null&&t.sync),r=Object.keys(s);return r.forEach(o=>{if(Object.getOwnPropertyDescriptor(e,o))throw new Error("object property already defined");const l=s[o];let i=null;const u=()=>{if(i&&(Array.from(i).map(([c])=>z(c,u)).some(c=>c)||Array.from(i).every(([c,h])=>x(c)===h.v)))return;const a=new Map,d=l(c=>(a.set(c,{v:x(c)}),c)),p=()=>{a.forEach((c,h)=>{var m;const w=(m=i==null?void 0:i.get(h))==null?void 0:m.s;if(w)c.s=w;else{const f={s:h,d:e,k:o,c:u,n,i:r};k(f),c.s=f}}),i==null||i.forEach((c,h)=>{!a.has(h)&&c.s&&A(c.s)}),i=a};d instanceof Promise?d.finally(p):p(),e[o]=d};u()}),e}function R(s,t){const e=t!=null&&t.delete?new Set:null;C(s).forEach(n=>{const{k:r}=n;(!(t!=null&&t.keys)||t.keys.includes(r))&&(A(n),e&&e.add(r))}),e&&e.forEach(n=>{delete s[n]})}function W(s,t,e=s){const n={};return Object.keys(t).forEach(r=>{n[r]=o=>t[r](o(s))}),N(n,{proxy:e})}function U(s,t){Object.keys(t).forEach(n=>{if(Object.getOwnPropertyDescriptor(s,n))throw new Error("object property already defined");const r=t[n],{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(s,n,i)});const e=b(s);return e}const L=s=>typeof s=="object"&&s!==null,P=s=>{if(!L(s))return s;const t=Array.isArray(s)?[]:Object.create(Object.getPrototypeOf(s));return Reflect.ownKeys(s).forEach(e=>{t[e]=P(s[e])}),t};function K(s,t=!1){const e=b({value:s,history:_({wip:void 0,snapshots:[],index:-1}),canUndo:()=>e.history.index>0,undo:()=>{e.canUndo()&&(e.value=e.history.wip=P(e.history.snapshots[--e.history.index]))},canRedo:()=>e.history.index<e.history.snapshots.length-1,redo:()=>{e.canRedo()&&(e.value=e.history.wip=P(e.history.snapshots[++e.history.index]))},saveHistory:()=>{e.history.snapshots.splice(e.history.index+1),e.history.snapshots.push(y(e).value),++e.history.index},subscribe:()=>O(e,n=>{n.every(r=>r[1][0]==="value"&&(r[0]!=="set"||r[2]!==e.history.wip))&&e.saveHistory()})});return e.saveHistory(),t||e.subscribe(),e}function V(s){const t=b({data:Array.from(new Set(s)),has(e){return this.data.indexOf(e)!==-1},add(e){let n=!1;return typeof e=="object"&&e!==null&&(n=this.data.indexOf(b(e))!==-1),this.data.indexOf(e)===-1&&!n&&this.data.push(e),this},delete(e){const n=this.data.indexOf(e);return n===-1?!1:(this.data.splice(n,1),!0)},clear(){this.data.splice(0)},get size(){return this.data.length},forEach(e){this.data.forEach(n=>{e(n,n,this)})},get[Symbol.toStringTag](){return"Set"},toJSON(){return new Set(this.data)},[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(t,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(t),t}function X(s){const t=b({data:Array.from(s||[]),has(e){return this.data.some(n=>n[0]===e)},set(e,n){const r=this.data.find(o=>o[0]===e);return r?r[1]=n:this.data.push([e,n]),this},get(e){var n;return(n=this.data.find(r=>r[0]===e))==null?void 0:n[1]},delete(e){const n=this.data.findIndex(r=>r[0]===e);return n===-1?!1:(this.data.splice(n,1),!0)},clear(){this.data.splice(0)},get size(){return this.data.length},toJSON(){return new Map(this.data)},forEach(e){this.data.forEach(n=>{e(n[1],n[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(t,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(t),t}}}}); |
@@ -1,3 +0,3 @@ | ||
export * from './vanilla'; | ||
export * from './react'; | ||
export * from 'valtio/vanilla'; | ||
export * from 'valtio/react'; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
@@ -1,2 +0,2 @@ | ||
import { INTERNAL_Snapshot as Snapshot } from './vanilla'; | ||
import { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
type Options = { | ||
@@ -3,0 +3,0 @@ sync?: boolean; |
@@ -1,3 +0,3 @@ | ||
export * from './vanilla/utils'; | ||
export * from './react/utils'; | ||
export * from 'valtio/vanilla/utils'; | ||
export * from 'valtio/react/utils'; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
@@ -6,3 +6,3 @@ export { subscribeKey } from './utils/subscribeKey'; | ||
export { addComputed_DEPRECATED as addComputed } from './utils/addComputed'; | ||
export { proxyWithComputed } from './utils/proxyWithComputed'; | ||
export { proxyWithComputed_DEPRECATED as proxyWithComputed } from './utils/proxyWithComputed'; | ||
export { proxyWithHistory } from './utils/proxyWithHistory'; | ||
@@ -9,0 +9,0 @@ export { proxySet } from './utils/proxySet'; |
@@ -1,27 +0,8 @@ | ||
import { INTERNAL_Snapshot as Snapshot } from '../../vanilla'; | ||
import { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
/** | ||
* proxyWithComputed | ||
* proxyWithComputed (DEPRECATED) | ||
* | ||
* This is to create a proxy with initial object and additional object, | ||
* which specifies getters for computed values with dependency tracking. | ||
* It also accepts optional setters for computed values. | ||
* | ||
* [Notes] | ||
* This comes with a cost and overlaps with useSnapshot. | ||
* Do not try to optimize too early. It can worsen the performance. | ||
* Measurement and comparison will be very important. | ||
* | ||
* @example | ||
* import { proxyWithComputed } from 'valtio/utils' | ||
* const state = proxyWithComputed({ | ||
* count: 1, | ||
* }, { | ||
* doubled: snap => snap.count * 2, // getter only | ||
* tripled: { | ||
* get: snap => snap.count * 3, | ||
* set: (state, newValue) => { state.count = newValue / 3 } | ||
* }, // with optional setter | ||
* }) | ||
* @deprecated Please follow "Computed Properties" guide in docs. | ||
*/ | ||
export declare function proxyWithComputed<T extends object, U extends object>(initialObject: T, computedFns: { | ||
export declare function proxyWithComputed_DEPRECATED<T extends object, U extends object>(initialObject: T, computedFns: { | ||
[K in keyof U]: ((snap: Snapshot<T>) => U[K]) | { | ||
@@ -28,0 +9,0 @@ get: (snap: Snapshot<T>) => U[K]; |
@@ -1,2 +0,2 @@ | ||
import { INTERNAL_Snapshot as Snapshot } from '../../vanilla'; | ||
import { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
type SnapshotOrUndefined<T> = Snapshot<T> | undefined; | ||
@@ -3,0 +3,0 @@ type Snapshots<T> = Snapshot<T>[]; |
@@ -1,3 +0,3 @@ | ||
export * from './vanilla'; | ||
export * from './react'; | ||
export * from 'valtio/vanilla'; | ||
export * from 'valtio/react'; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
@@ -1,2 +0,2 @@ | ||
import { INTERNAL_Snapshot as Snapshot } from './vanilla'; | ||
import { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
type Options = { | ||
@@ -3,0 +3,0 @@ sync?: boolean; |
@@ -1,3 +0,3 @@ | ||
export * from './vanilla/utils'; | ||
export * from './react/utils'; | ||
export * from 'valtio/vanilla/utils'; | ||
export * from 'valtio/react/utils'; | ||
declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
@@ -6,3 +6,3 @@ export { subscribeKey } from './utils/subscribeKey'; | ||
export { addComputed_DEPRECATED as addComputed } from './utils/addComputed'; | ||
export { proxyWithComputed } from './utils/proxyWithComputed'; | ||
export { proxyWithComputed_DEPRECATED as proxyWithComputed } from './utils/proxyWithComputed'; | ||
export { proxyWithHistory } from './utils/proxyWithHistory'; | ||
@@ -9,0 +9,0 @@ export { proxySet } from './utils/proxySet'; |
@@ -1,27 +0,8 @@ | ||
import { INTERNAL_Snapshot as Snapshot } from '../../vanilla'; | ||
import { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
/** | ||
* proxyWithComputed | ||
* proxyWithComputed (DEPRECATED) | ||
* | ||
* This is to create a proxy with initial object and additional object, | ||
* which specifies getters for computed values with dependency tracking. | ||
* It also accepts optional setters for computed values. | ||
* | ||
* [Notes] | ||
* This comes with a cost and overlaps with useSnapshot. | ||
* Do not try to optimize too early. It can worsen the performance. | ||
* Measurement and comparison will be very important. | ||
* | ||
* @example | ||
* import { proxyWithComputed } from 'valtio/utils' | ||
* const state = proxyWithComputed({ | ||
* count: 1, | ||
* }, { | ||
* doubled: snap => snap.count * 2, // getter only | ||
* tripled: { | ||
* get: snap => snap.count * 3, | ||
* set: (state, newValue) => { state.count = newValue / 3 } | ||
* }, // with optional setter | ||
* }) | ||
* @deprecated Please follow "Computed Properties" guide in docs. | ||
*/ | ||
export declare function proxyWithComputed<T extends object, U extends object>(initialObject: T, computedFns: { | ||
export declare function proxyWithComputed_DEPRECATED<T extends object, U extends object>(initialObject: T, computedFns: { | ||
[K in keyof U]: ((snap: Snapshot<T>) => U[K]) | { | ||
@@ -28,0 +9,0 @@ get: (snap: Snapshot<T>) => U[K]; |
@@ -1,2 +0,2 @@ | ||
import { INTERNAL_Snapshot as Snapshot } from '../../vanilla'; | ||
import { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
type SnapshotOrUndefined<T> = Snapshot<T> | undefined; | ||
@@ -3,0 +3,0 @@ type Snapshots<T> = Snapshot<T>[]; |
@@ -188,3 +188,3 @@ (function (global, factory) { | ||
var prevValue = Reflect.get(target, prop, receiver); | ||
if (hasPrevValue && objectIs(prevValue, value)) { | ||
if (hasPrevValue && (objectIs(prevValue, value) || proxyCache.has(value) && objectIs(prevValue, proxyCache.get(value)))) { | ||
return true; | ||
@@ -191,0 +191,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("proxy-compare")):"function"==typeof define&&define.amd?define(["exports","proxy-compare"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).valtio={},e.proxyCompare)}(this,(function(e,t){"use strict";var r=function(e){return"object"==typeof e&&null!==e},n=new WeakMap,o=new WeakSet,i=function(e,i,c,u,s,l,v,d,p){return void 0===e&&(e=Object.is),void 0===i&&(i=function(e,t){return new Proxy(e,t)}),void 0===c&&(c=function(e){return r(e)&&!o.has(e)&&(Array.isArray(e)||!(Symbol.iterator in e))&&!(e instanceof WeakMap)&&!(e instanceof WeakSet)&&!(e instanceof Error)&&!(e instanceof Number)&&!(e instanceof Date)&&!(e instanceof String)&&!(e instanceof RegExp)&&!(e instanceof ArrayBuffer)}),void 0===u&&(u=function(e){switch(e.status){case"fulfilled":return e.value;case"rejected":throw e.reason;default:throw e}}),void 0===s&&(s=new WeakMap),void 0===l&&(l=function(e,r,i){void 0===i&&(i=u);var c=s.get(e);if((null==c?void 0:c[0])===r)return c[1];var a=Array.isArray(e)?[]:Object.create(Object.getPrototypeOf(e));return t.markToTrack(a,!0),s.set(e,[r,a]),Reflect.ownKeys(e).forEach((function(r){var c=Reflect.get(e,r);o.has(c)?(t.markToTrack(c,!1),a[r]=c):c instanceof Promise?Object.defineProperty(a,r,{get:function(){return i(c)}}):n.has(c)?a[r]=f(c,i):a[r]=c})),Object.freeze(a)}),void 0===v&&(v=new WeakMap),void 0===d&&(d=[1,1]),void 0===p&&(p=function(f){if(!r(f))throw new Error("object required");var u=v.get(f);if(u)return u;var s=d[0],p=new Set,y=function(e,t){void 0===t&&(t=++d[0]),s!==t&&(s=t,p.forEach((function(r){return r(e,t)})))},h=d[1],g=function(e){return function(t,r){var n=[].concat(t);n[1]=[e].concat(n[1]),y(n,r)}},b=new Map,j=function(e){var t,r=b.get(e);r&&(b.delete(e),null==(t=r[1])||t.call(r))},w=Array.isArray(f)?[]:Object.create(Object.getPrototypeOf(f)),O=i(w,{deleteProperty:function(e,t){var r=Reflect.get(e,t);j(t);var n=Reflect.deleteProperty(e,t);return n&&y(["delete",[t],r]),n},set:function(i,f,u,s){var l,v=Reflect.has(i,f),d=Reflect.get(i,f,s);if(v&&e(d,u))return!0;j(f),r(u)&&(u=t.getUntracked(u)||u);var h=u;if(null!=(l=Object.getOwnPropertyDescriptor(i,f))&&l.set);else if(u instanceof Promise)u.then((function(e){u.status="fulfilled",u.value=e,y(["resolve",[f],e])})).catch((function(e){u.status="rejected",u.reason=e,y(["reject",[f],e])}));else{!n.has(u)&&c(u)&&(h=a(u));var w=!o.has(h)&&n.get(h);w&&function(e,t){if(p.size){var r=t[3](g(e));b.set(e,[t,r])}else b.set(e,[t])}(f,w)}return Reflect.set(i,f,h,s),y(["set",[f],u,d]),!0}});v.set(f,O);var P=[w,function(e){return void 0===e&&(e=++d[1]),h===e||p.size||(h=e,b.forEach((function(t){var r=t[0][1](e);r>s&&(s=r)}))),s},l,function(e){p.add(e),1===p.size&&b.forEach((function(e,t){var r=e[0];e[1];var n=r[3](g(t));b.set(t,[r,n])}));return function(){p.delete(e),0===p.size&&b.forEach((function(e,t){var r=e[0],n=e[1];n&&(n(),b.set(t,[r]))}))}}];return n.set(O,P),Reflect.ownKeys(f).forEach((function(e){var t=Object.getOwnPropertyDescriptor(f,e);t.get||t.set?Object.defineProperty(w,e,t):O[e]=f[e]})),O}),[p,n,o,e,i,c,u,s,l,v,d]},c=i()[0];function a(e){return void 0===e&&(e={}),c(e)}function f(e,t){var r=n.get(e),o=r[0],i=r[1];return(0,r[2])(o,i(),t)}var u=i;e.getVersion=function(e){var t=n.get(e);return null==t?void 0:t[1]()},e.proxy=a,e.ref=function(e){return o.add(e),e},e.snapshot=f,e.subscribe=function(e,t,r){var o,i=n.get(e),c=[],a=i[3],f=!1,u=a((function(e){c.push(e),r?t(c.splice(0)):o||(o=Promise.resolve().then((function(){o=void 0,f&&t(c.splice(0))})))}));return f=!0,function(){f=!1,u()}},e.unstable_buildProxyFunction=u})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("proxy-compare")):"function"==typeof define&&define.amd?define(["exports","proxy-compare"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).valtio={},e.proxyCompare)}(this,(function(e,t){"use strict";var r=function(e){return"object"==typeof e&&null!==e},n=new WeakMap,o=new WeakSet,i=function(e,i,c,u,s,l,v,d,p){return void 0===e&&(e=Object.is),void 0===i&&(i=function(e,t){return new Proxy(e,t)}),void 0===c&&(c=function(e){return r(e)&&!o.has(e)&&(Array.isArray(e)||!(Symbol.iterator in e))&&!(e instanceof WeakMap)&&!(e instanceof WeakSet)&&!(e instanceof Error)&&!(e instanceof Number)&&!(e instanceof Date)&&!(e instanceof String)&&!(e instanceof RegExp)&&!(e instanceof ArrayBuffer)}),void 0===u&&(u=function(e){switch(e.status){case"fulfilled":return e.value;case"rejected":throw e.reason;default:throw e}}),void 0===s&&(s=new WeakMap),void 0===l&&(l=function(e,r,i){void 0===i&&(i=u);var c=s.get(e);if((null==c?void 0:c[0])===r)return c[1];var a=Array.isArray(e)?[]:Object.create(Object.getPrototypeOf(e));return t.markToTrack(a,!0),s.set(e,[r,a]),Reflect.ownKeys(e).forEach((function(r){var c=Reflect.get(e,r);o.has(c)?(t.markToTrack(c,!1),a[r]=c):c instanceof Promise?Object.defineProperty(a,r,{get:function(){return i(c)}}):n.has(c)?a[r]=f(c,i):a[r]=c})),Object.freeze(a)}),void 0===v&&(v=new WeakMap),void 0===d&&(d=[1,1]),void 0===p&&(p=function(f){if(!r(f))throw new Error("object required");var u=v.get(f);if(u)return u;var s=d[0],p=new Set,y=function(e,t){void 0===t&&(t=++d[0]),s!==t&&(s=t,p.forEach((function(r){return r(e,t)})))},h=d[1],g=function(e){return function(t,r){var n=[].concat(t);n[1]=[e].concat(n[1]),y(n,r)}},b=new Map,j=function(e){var t,r=b.get(e);r&&(b.delete(e),null==(t=r[1])||t.call(r))},w=Array.isArray(f)?[]:Object.create(Object.getPrototypeOf(f)),O=i(w,{deleteProperty:function(e,t){var r=Reflect.get(e,t);j(t);var n=Reflect.deleteProperty(e,t);return n&&y(["delete",[t],r]),n},set:function(i,f,u,s){var l,d=Reflect.has(i,f),h=Reflect.get(i,f,s);if(d&&(e(h,u)||v.has(u)&&e(h,v.get(u))))return!0;j(f),r(u)&&(u=t.getUntracked(u)||u);var w=u;if(null!=(l=Object.getOwnPropertyDescriptor(i,f))&&l.set);else if(u instanceof Promise)u.then((function(e){u.status="fulfilled",u.value=e,y(["resolve",[f],e])})).catch((function(e){u.status="rejected",u.reason=e,y(["reject",[f],e])}));else{!n.has(u)&&c(u)&&(w=a(u));var O=!o.has(w)&&n.get(w);O&&function(e,t){if(p.size){var r=t[3](g(e));b.set(e,[t,r])}else b.set(e,[t])}(f,O)}return Reflect.set(i,f,w,s),y(["set",[f],u,h]),!0}});v.set(f,O);var P=[w,function(e){return void 0===e&&(e=++d[1]),h===e||p.size||(h=e,b.forEach((function(t){var r=t[0][1](e);r>s&&(s=r)}))),s},l,function(e){p.add(e),1===p.size&&b.forEach((function(e,t){var r=e[0];e[1];var n=r[3](g(t));b.set(t,[r,n])}));return function(){p.delete(e),0===p.size&&b.forEach((function(e,t){var r=e[0],n=e[1];n&&(n(),b.set(t,[r]))}))}}];return n.set(O,P),Reflect.ownKeys(f).forEach((function(e){var t=Object.getOwnPropertyDescriptor(f,e);t.get||t.set?Object.defineProperty(w,e,t):O[e]=f[e]})),O}),[p,n,o,e,i,c,u,s,l,v,d]},c=i()[0];function a(e){return void 0===e&&(e={}),c(e)}function f(e,t){var r=n.get(e),o=r[0],i=r[1];return(0,r[2])(o,i(),t)}var u=i;e.getVersion=function(e){var t=n.get(e);return null==t?void 0:t[1]()},e.proxy=a,e.ref=function(e){return o.add(e),e},e.snapshot=f,e.subscribe=function(e,t,r){var o,i=n.get(e),c=[],a=i[3],f=!1,u=a((function(e){c.push(e),r?t(c.splice(0)):o||(o=Promise.resolve().then((function(){o=void 0,f&&t(c.splice(0))})))}));return f=!0,function(){f=!1,u()}},e.unstable_buildProxyFunction=u})); |
@@ -91,3 +91,3 @@ (function (global, factory) { | ||
try { | ||
extension = (enabled != null ? enabled : true) && window.__REDUX_DEVTOOLS_EXTENSION__; | ||
extension = (enabled != null ? enabled : "development" !== 'production') && window.__REDUX_DEVTOOLS_EXTENSION__; | ||
} catch (_unused) {} | ||
@@ -383,3 +383,5 @@ if (!extension) { | ||
} | ||
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'); | ||
{ | ||
console.warn('addComputed is deprecated. Please consider using `derive`. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201'); | ||
} | ||
var derivedFns = {}; | ||
@@ -396,3 +398,6 @@ Object.keys(computedFns_FAKE).forEach(function (key) { | ||
function proxyWithComputed(initialObject, computedFns) { | ||
function proxyWithComputed_DEPRECATED(initialObject, computedFns) { | ||
{ | ||
console.warn('proxyWithComputed is deprecated. Please follow "Computed Properties" guide in docs.'); | ||
} | ||
Object.keys(computedFns).forEach(function (key) { | ||
@@ -647,3 +652,3 @@ if (Object.getOwnPropertyDescriptor(initialObject, key)) { | ||
exports.proxySet = proxySet; | ||
exports.proxyWithComputed = proxyWithComputed; | ||
exports.proxyWithComputed = proxyWithComputed_DEPRECATED; | ||
exports.proxyWithHistory = proxyWithHistory; | ||
@@ -650,0 +655,0 @@ exports.subscribeKey = subscribeKey; |
@@ -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))},u=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)})))},s=function(t){var n=t.s,r=t.d,s=a.get(r);s||(s=[new Set],a.set(t.d,s)),s[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,s=e.i;n===r&&t.every((function(t){return 1===t[1].length&&s.includes(t[1][0])}))||e.p||(o(n,i),a?u(n):e.p=Promise.resolve().then((function(){delete e.p,u(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 u=o[0],s=o[1];u.delete(t),u.size||(s(),i.delete(e))}},f=function(t){var e=a.get(t);return e?Array.from(e[0]):[]},d={add:s,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 u=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=u((function(t){return d.set(t,{v:e.getVersion(t)}),t})),p=function(){var e;d.forEach((function(e,i){var u,c,d=null==(u=f)||null==(c=u.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};s(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}var p=function t(e){if("object"!=typeof(n=e)||null===n)return e;var n,r=Array.isArray(e)?[]:Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach((function(n){r[n]=t(e[n])})),r};function h(t,e,n,r){var i={configurable:!0,enumerable:!0};return i[t]=r,Object.defineProperty(e,n,i)}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))}})),l(r,{proxy:n})},t.derive=l,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,u=a.name,s=void 0===u?"":u;try{i=null!=o&&o&&window.__REDUX_DEVTOOLS_EXTENSION__}catch(t){}if(i){var c=!1,f=i.connect({name:s}),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,u;if("JUMP_TO_ACTION"===(null==(o=n.payload)?void 0:o.type)||"JUMP_TO_STATE"===(null==(u=n.payload)?void 0:u.type)){c=!0;var s=JSON.parse(n.state);Object.assign(t,s)}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=e.proxy((h("get",n={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 new Map(this.data)},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()}},Symbol.toStringTag,(function(){return"Map"})),n[Symbol.iterator]=function(){return this.entries()},n));return Object.defineProperties(r,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(r),r},t.proxySet=function(t){var n,r=e.proxy((h("get",n={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)}))}},Symbol.toStringTag,(function(){return"Set"})),n.toJSON=function(){return new Set(this.data)},n[Symbol.iterator]=function(){return this.data[Symbol.iterator]()},n.values=function(){return this.data.values()},n.keys=function(){return this.data.values()},n.entries=function(){return new Set(this.data).entries()},n));return Object.defineProperties(r,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(r),r},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,u=o.get,s=o.set,c={get:function(){return u(e.snapshot(r))}};s&&(c.set=function(t){return s(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:void 0,snapshots:[],index:-1}),canUndo:function(){return r.history.index>0},undo:function(){r.canUndo()&&(r.value=r.history.wip=p(r.history.snapshots[--r.history.index]))},canRedo:function(){return r.history.index<r.history.snapshots.length-1},redo:function(){r.canRedo()&&(r.value=r.history.wip=p(r.history.snapshots[++r.history.index]))},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){var a=t[n];return e.subscribe(t,(function(){var e=t[n];Object.is(a,e)||r(a=e)}),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,u=function(){i&&(i=!1,a.forEach((function(t){return t()})),a.clear(),o.forEach((function(t){return t()})),o.clear())};return n&&n.add(u),function u(){if(i){a.forEach((function(t){return t()})),a.clear();var s=new Set,c=n;n=a;try{var f=t((function(t){return s.add(t),t}));f&&a.add(f)}finally{n=c}o.forEach((function(t,e){s.has(e)?s.delete(e):(o.delete(e),t())})),s.forEach((function(t){var n=e.subscribe(t,u,null==r?void 0:r.sync);o.set(t,n)}))}}(),u}})); | ||
!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))},u=function(t,e){var n=i.get(t);return!(null==n||!n[2])&&(n[3].add(e),!0)},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)})))},c=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)},f=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 u=o[0],s=o[1];u.delete(t),u.size||(s(),i.delete(e))}},d=function(t){var e=a.get(t);return e?Array.from(e[0]):[]},l={add:c,remove:f,list:d};function p(t,n){var r=(null==n?void 0:n.proxy)||e.proxy({}),i=!(null==n||!n.sync),a=Object.keys(t);return a.forEach((function(n){if(Object.getOwnPropertyDescriptor(r,n))throw new Error("object property already defined");var o=t[n],s=null;!function t(){if(s){if(Array.from(s).map((function(e){var n=e[0];return u(n,t)})).some((function(t){return t})))return;if(Array.from(s).every((function(t){var n=t[0],r=t[1];return e.getVersion(n)===r.v})))return}var d=new Map,l=o((function(t){return d.set(t,{v:e.getVersion(t)}),t})),p=function(){var e;d.forEach((function(e,o){var u,f,d=null==(u=s)||null==(f=u.get(o))?void 0:f.s;if(d)e.s=d;else{var l={s:o,d:r,k:n,c:t,n:i,i:a};c(l),e.s=l}})),null==(e=s)||e.forEach((function(t,e){!d.has(e)&&t.s&&f(t.s)})),s=d};l instanceof Promise?l.finally(p):p(),r[n]=l}()})),r}var h=function t(e){if("object"!=typeof(n=e)||null===n)return e;var n,r=Array.isArray(e)?[]:Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach((function(n){r[n]=t(e[n])})),r};function v(t,e,n,r){var i={configurable:!0,enumerable:!0};return i[t]=r,Object.defineProperty(e,n,i)}t.addComputed=function(t,e,n){void 0===n&&(n=t);var r={};return Object.keys(e).forEach((function(n){r[n]=function(r){return e[n](r(t))}})),p(r,{proxy:n})},t.derive=p,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,u=a.name,s=void 0===u?"":u;try{i=null!=o&&o&&window.__REDUX_DEVTOOLS_EXTENSION__}catch(t){}if(i){var c=!1,f=i.connect({name:s}),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,u;if("JUMP_TO_ACTION"===(null==(o=n.payload)?void 0:o.type)||"JUMP_TO_STATE"===(null==(u=n.payload)?void 0:u.type)){c=!0;var s=JSON.parse(n.state);Object.assign(t,s)}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=e.proxy((v("get",n={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 new Map(this.data)},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()}},Symbol.toStringTag,(function(){return"Map"})),n[Symbol.iterator]=function(){return this.entries()},n));return Object.defineProperties(r,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(r),r},t.proxySet=function(t){var n,r=e.proxy((v("get",n={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)}))}},Symbol.toStringTag,(function(){return"Set"})),n.toJSON=function(){return new Set(this.data)},n[Symbol.iterator]=function(){return this.data[Symbol.iterator]()},n.values=function(){return this.data.values()},n.keys=function(){return this.data.values()},n.entries=function(){return new Set(this.data).entries()},n));return Object.defineProperties(r,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(r),r},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,u=o.get,s=o.set,c={get:function(){return u(e.snapshot(r))}};s&&(c.set=function(t){return s(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:void 0,snapshots:[],index:-1}),canUndo:function(){return r.history.index>0},undo:function(){r.canUndo()&&(r.value=r.history.wip=h(r.history.snapshots[--r.history.index]))},canRedo:function(){return r.history.index<r.history.snapshots.length-1},redo:function(){r.canRedo()&&(r.value=r.history.wip=h(r.history.snapshots[++r.history.index]))},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){var a=t[n];return e.subscribe(t,(function(){var e=t[n];Object.is(a,e)||r(a=e)}),i)},t.underive=function(t,e){var n=null!=e&&e.delete?new Set:null;d(t).forEach((function(t){var r=t.k;null!=e&&e.keys&&!e.keys.includes(r)||(f(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,u=function(){i&&(i=!1,a.forEach((function(t){return t()})),a.clear(),o.forEach((function(t){return t()})),o.clear())};return n&&n.add(u),function u(){if(i){a.forEach((function(t){return t()})),a.clear();var s=new Set,c=n;n=a;try{var f=t((function(t){return s.add(t),t}));f&&a.add(f)}finally{n=c}o.forEach((function(t,e){s.has(e)?s.delete(e):(o.delete(e),t())})),s.forEach((function(t){var n=e.subscribe(t,u,null==r?void 0:r.sync);o.set(t,n)}))}}(),u}})); |
@@ -1,2 +0,2 @@ | ||
export * from './vanilla/utils'; | ||
export * from './react/utils'; | ||
export * from 'valtio/vanilla/utils'; | ||
export * from 'valtio/react/utils'; |
@@ -125,3 +125,3 @@ 'use strict'; | ||
var addPropListener = function addPropListener(prop, propProxyState) { | ||
if (process.env.NODE_ENV !== "production" && propProxyStates.has(prop)) { | ||
if (process.env.NODE_ENV !== 'production' && propProxyStates.has(prop)) { | ||
throw new Error('prop listener already exists'); | ||
@@ -150,3 +150,3 @@ } | ||
prevRemove = _ref2[1]; | ||
if (process.env.NODE_ENV !== "production" && prevRemove) { | ||
if (process.env.NODE_ENV !== 'production' && prevRemove) { | ||
throw new Error('remove already exists'); | ||
@@ -188,3 +188,3 @@ } | ||
var prevValue = Reflect.get(target, prop, receiver); | ||
if (hasPrevValue && objectIs(prevValue, value)) { | ||
if (hasPrevValue && (objectIs(prevValue, value) || proxyCache.has(value) && objectIs(prevValue, proxyCache.get(value)))) { | ||
return true; | ||
@@ -252,3 +252,3 @@ } | ||
var proxyState = proxyStateMap.get(proxyObject); | ||
if (process.env.NODE_ENV !== "production" && !proxyState) { | ||
if (process.env.NODE_ENV !== 'production' && !proxyState) { | ||
console.warn('Please use proxy object'); | ||
@@ -284,3 +284,3 @@ } | ||
var proxyState = proxyStateMap.get(proxyObject); | ||
if (process.env.NODE_ENV !== "production" && !proxyState) { | ||
if (process.env.NODE_ENV !== 'production' && !proxyState) { | ||
console.warn('Please use proxy object'); | ||
@@ -287,0 +287,0 @@ } |
@@ -6,5 +6,5 @@ export { subscribeKey } from './utils/subscribeKey'; | ||
export { addComputed_DEPRECATED as addComputed } from './utils/addComputed'; | ||
export { proxyWithComputed } from './utils/proxyWithComputed'; | ||
export { proxyWithComputed_DEPRECATED as proxyWithComputed } from './utils/proxyWithComputed'; | ||
export { proxyWithHistory } from './utils/proxyWithHistory'; | ||
export { proxySet } from './utils/proxySet'; | ||
export { proxyMap } from './utils/proxyMap'; |
@@ -89,6 +89,6 @@ 'use strict'; | ||
try { | ||
extension = (enabled != null ? enabled : process.env.NODE_ENV !== "production") && window.__REDUX_DEVTOOLS_EXTENSION__; | ||
extension = (enabled != null ? enabled : process.env.NODE_ENV !== 'production') && window.__REDUX_DEVTOOLS_EXTENSION__; | ||
} catch (_unused) {} | ||
if (!extension) { | ||
if (process.env.NODE_ENV !== "production" && enabled) { | ||
if (process.env.NODE_ENV !== 'production' && enabled) { | ||
console.warn('[Warning] Please install/enable Redux devtools extension'); | ||
@@ -381,3 +381,5 @@ } | ||
} | ||
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'); | ||
if (process.env.NODE_ENV !== 'production') { | ||
console.warn('addComputed is deprecated. Please consider using `derive`. Falling back to emulation with derive. https://github.com/pmndrs/valtio/pull/201'); | ||
} | ||
var derivedFns = {}; | ||
@@ -394,3 +396,6 @@ Object.keys(computedFns_FAKE).forEach(function (key) { | ||
function proxyWithComputed(initialObject, computedFns) { | ||
function proxyWithComputed_DEPRECATED(initialObject, computedFns) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
console.warn('proxyWithComputed is deprecated. Please follow "Computed Properties" guide in docs.'); | ||
} | ||
Object.keys(computedFns).forEach(function (key) { | ||
@@ -645,3 +650,3 @@ if (Object.getOwnPropertyDescriptor(initialObject, key)) { | ||
exports.proxySet = proxySet; | ||
exports.proxyWithComputed = proxyWithComputed; | ||
exports.proxyWithComputed = proxyWithComputed_DEPRECATED; | ||
exports.proxyWithHistory = proxyWithHistory; | ||
@@ -648,0 +653,0 @@ exports.subscribeKey = subscribeKey; |
@@ -1,27 +0,8 @@ | ||
import type { INTERNAL_Snapshot as Snapshot } from '../../vanilla'; | ||
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
/** | ||
* proxyWithComputed | ||
* proxyWithComputed (DEPRECATED) | ||
* | ||
* This is to create a proxy with initial object and additional object, | ||
* which specifies getters for computed values with dependency tracking. | ||
* It also accepts optional setters for computed values. | ||
* | ||
* [Notes] | ||
* This comes with a cost and overlaps with useSnapshot. | ||
* Do not try to optimize too early. It can worsen the performance. | ||
* Measurement and comparison will be very important. | ||
* | ||
* @example | ||
* import { proxyWithComputed } from 'valtio/utils' | ||
* const state = proxyWithComputed({ | ||
* count: 1, | ||
* }, { | ||
* doubled: snap => snap.count * 2, // getter only | ||
* tripled: { | ||
* get: snap => snap.count * 3, | ||
* set: (state, newValue) => { state.count = newValue / 3 } | ||
* }, // with optional setter | ||
* }) | ||
* @deprecated Please follow "Computed Properties" guide in docs. | ||
*/ | ||
export declare function proxyWithComputed<T extends object, U extends object>(initialObject: T, computedFns: { | ||
export declare function proxyWithComputed_DEPRECATED<T extends object, U extends object>(initialObject: T, computedFns: { | ||
[K in keyof U]: ((snap: Snapshot<T>) => U[K]) | { | ||
@@ -28,0 +9,0 @@ get: (snap: Snapshot<T>) => U[K]; |
@@ -1,2 +0,2 @@ | ||
import type { INTERNAL_Snapshot as Snapshot } from '../../vanilla'; | ||
import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
type SnapshotOrUndefined<T> = Snapshot<T> | undefined; | ||
@@ -3,0 +3,0 @@ type Snapshots<T> = Snapshot<T>[]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
311530
7349
399
22