Comparing version 1.10.5 to 1.10.6
@@ -1,2 +0,2 @@ | ||
import { subscribe, snapshot, proxy, getVersion, ref } from 'valtio/vanilla'; | ||
import { subscribe, snapshot, proxy, getVersion, ref, unstable_buildProxyFunction } from 'valtio/vanilla'; | ||
@@ -79,3 +79,3 @@ function subscribeKey(proxyObject, key, callback, notifyInSync) { | ||
} | ||
const { enabled, name = "" } = options || {}; | ||
const { enabled, name = "", ...rest } = options || {}; | ||
let extension; | ||
@@ -93,3 +93,3 @@ try { | ||
let isTimeTraveling = false; | ||
const devtools2 = extension.connect({ name }); | ||
const devtools2 = extension.connect({ name, ...rest }); | ||
const unsub1 = subscribe(proxyObject, (ops) => { | ||
@@ -398,4 +398,8 @@ const action = ops.filter(([_, path]) => path[0] !== DEVTOOLS).map(([op, path]) => `${op}:${path.map(String).join(".")}`).join(", "); | ||
const isObject = (x) => typeof x === "object" && x !== null; | ||
let refSet; | ||
const deepClone = (obj) => { | ||
if (!isObject(obj)) { | ||
if (!refSet) { | ||
refSet = unstable_buildProxyFunction()[2]; | ||
} | ||
if (!isObject(obj) || refSet.has(obj)) { | ||
return obj; | ||
@@ -418,6 +422,7 @@ } | ||
}), | ||
clone: deepClone, | ||
canUndo: () => proxyObject.history.index > 0, | ||
undo: () => { | ||
if (proxyObject.canUndo()) { | ||
proxyObject.value = proxyObject.history.wip = deepClone( | ||
proxyObject.value = proxyObject.history.wip = proxyObject.clone( | ||
proxyObject.history.snapshots[--proxyObject.history.index] | ||
@@ -430,3 +435,3 @@ ); | ||
if (proxyObject.canRedo()) { | ||
proxyObject.value = proxyObject.history.wip = deepClone( | ||
proxyObject.value = proxyObject.history.wip = proxyObject.clone( | ||
proxyObject.history.snapshots[++proxyObject.history.index] | ||
@@ -433,0 +438,0 @@ ); |
@@ -0,5 +1,6 @@ | ||
type EnhancerOptions = Parameters<NonNullable<(typeof window)['__REDUX_DEVTOOLS_EXTENSION__']>['connect']>[0]; | ||
type Options = { | ||
enabled?: boolean; | ||
name?: string; | ||
}; | ||
} & EnhancerOptions; | ||
export declare function devtools<T extends object>(proxyObject: T, options?: Options): (() => void) | undefined; | ||
@@ -6,0 +7,0 @@ /** |
@@ -36,2 +36,3 @@ import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
}; | ||
clone: <T>(obj: T) => T; | ||
canUndo: () => boolean; | ||
@@ -38,0 +39,0 @@ undo: () => void; |
{ | ||
"name": "valtio", | ||
"private": false, | ||
"version": "1.10.5", | ||
"version": "1.10.6", | ||
"description": "💊 Valtio makes proxy-state simple for React and Vanilla", | ||
@@ -6,0 +6,0 @@ "main": "./index.js", |
System.register(['valtio/vanilla'], (function (exports) { | ||
'use strict'; | ||
var subscribe, snapshot, proxy, getVersion, ref; | ||
var subscribe, snapshot, proxy, getVersion, ref, unstable_buildProxyFunction; | ||
return { | ||
@@ -11,2 +11,3 @@ setters: [function (module) { | ||
ref = module.ref; | ||
unstable_buildProxyFunction = module.unstable_buildProxyFunction; | ||
}], | ||
@@ -104,3 +105,3 @@ execute: (function () { | ||
} | ||
const { enabled, name = "" } = options || {}; | ||
const { enabled, name = "", ...rest } = options || {}; | ||
let extension; | ||
@@ -118,3 +119,3 @@ try { | ||
let isTimeTraveling = false; | ||
const devtools2 = extension.connect({ name }); | ||
const devtools2 = extension.connect({ name, ...rest }); | ||
const unsub1 = subscribe(proxyObject, (ops) => { | ||
@@ -423,4 +424,8 @@ const action = ops.filter(([_, path]) => path[0] !== DEVTOOLS).map(([op, path]) => `${op}:${path.map(String).join(".")}`).join(", "); | ||
const isObject = (x) => typeof x === "object" && x !== null; | ||
let refSet; | ||
const deepClone = (obj) => { | ||
if (!isObject(obj)) { | ||
if (!refSet) { | ||
refSet = unstable_buildProxyFunction()[2]; | ||
} | ||
if (!isObject(obj) || refSet.has(obj)) { | ||
return obj; | ||
@@ -443,6 +448,7 @@ } | ||
}), | ||
clone: deepClone, | ||
canUndo: () => proxyObject.history.index > 0, | ||
undo: () => { | ||
if (proxyObject.canUndo()) { | ||
proxyObject.value = proxyObject.history.wip = deepClone( | ||
proxyObject.value = proxyObject.history.wip = proxyObject.clone( | ||
proxyObject.history.snapshots[--proxyObject.history.index] | ||
@@ -455,3 +461,3 @@ ); | ||
if (proxyObject.canRedo()) { | ||
proxyObject.value = proxyObject.history.wip = deepClone( | ||
proxyObject.value = proxyObject.history.wip = proxyObject.clone( | ||
proxyObject.history.snapshots[++proxyObject.history.index] | ||
@@ -458,0 +464,0 @@ ); |
@@ -1,2 +0,2 @@ | ||
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(([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(s));delete h[j],l.send({type:d,updatedAt:new Date().toLocaleString()},h)}}),u=l.subscribe(a=>{var d,h,c,p,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"||((h=a.payload)==null?void 0:h.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"&&((p=a.payload)==null?void 0:p.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:h,i:c}=u;t===a&&i.every(p=>p[1].length===1&&c.includes(p[1][0]))||u.p||(D(t,d),h?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,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 m;const w=(m=i==null?void 0:i.get(p))==null?void 0:m.s;if(w)c.s=w;else{const f={s:p,d:e,k:o,c:u,n,i:r};k(f),c.s=f}}),i==null||i.forEach((c,p)=>{!a.has(p)&&c.s&&A(c.s)}),i=a};d instanceof Promise?d.finally(h):h(),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}}}}); | ||
System.register(["valtio/vanilla"],function(M){"use strict";var S,p,b,j,D,k;return{setters:[function(f){S=f.subscribe,p=f.snapshot,b=f.proxy,j=f.getVersion,D=f.ref,k=f.unstable_buildProxyFunction}],execute:function(){M({addComputed:K,derive:J,devtools:W,proxyMap:B,proxySet:$,proxyWithComputed:V,proxyWithHistory:X,subscribeKey:f,underive:L,watch:R});function f(s,t,e,r){let n=s[t];return S(s,()=>{const i=s[t];Object.is(n,i)||e(n=i)},r)}let g;function R(s,t){let e=!0;const r=new Set,n=new Map,i=()=>{e&&(e=!1,r.forEach(o=>o()),r.clear(),n.forEach(o=>o()),n.clear())},d=()=>{if(!e)return;r.forEach(l=>l()),r.clear();const o=new Set,h=g;g=r;try{const l=s(a=>(o.add(a),a));l&&r.add(l)}finally{g=h}n.forEach((l,a)=>{o.has(a)?o.delete(a):(n.delete(a),l())}),o.forEach(l=>{const a=S(l,d,t==null?void 0:t.sync);n.set(l,a)})};return g&&g.add(i),d(),i}const T=Symbol();function W(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:r="",...n}=t||{};let i;try{i=(e!=null?e:!1)&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!i)return;let d=!1;const o=i.connect({name:r,...n}),h=S(s,a=>{const y=a.filter(([c,u])=>u[0]!==T).map(([c,u])=>`${c}:${u.map(String).join(".")}`).join(", ");if(y)if(d)d=!1;else{const c=Object.assign({},p(s));delete c[T],o.send({type:y,updatedAt:new Date().toLocaleString()},c)}}),l=o.subscribe(a=>{var y,c,u,E,m,w;if(a.type==="ACTION"&&a.payload)try{Object.assign(s,JSON.parse(a.payload))}catch(x){console.error(`please dispatch a serializable value that JSON.parse() and proxy() support | ||
`,x)}if(a.type==="DISPATCH"&&a.state){if(((y=a.payload)==null?void 0:y.type)==="JUMP_TO_ACTION"||((c=a.payload)==null?void 0:c.type)==="JUMP_TO_STATE"){d=!0;const x=JSON.parse(a.state);Object.assign(s,x)}s[T]=a}else if(a.type==="DISPATCH"&&((u=a.payload)==null?void 0:u.type)==="COMMIT")o.init(p(s));else if(a.type==="DISPATCH"&&((E=a.payload)==null?void 0:E.type)==="IMPORT_STATE"){const x=(m=a.payload.nextLiftedState)==null?void 0:m.actionsById,q=((w=a.payload.nextLiftedState)==null?void 0:w.computedStates)||[];d=!0,q.forEach(({state:G},z)=>{const Q=x[z]||"No action found";Object.assign(s,G),z===0?o.init(p(s)):o.send(Q,p(s))})}});return o.init(p(s)),()=>{h(),l==null||l()}}const v=new WeakMap,O=new WeakMap,C=(s,t)=>{const e=v.get(s);e&&(e[0].forEach(r=>{const{d:n}=r;s!==n&&C(n)}),++e[2],t&&e[3].add(t))},U=(s,t)=>{const e=v.get(s);return e!=null&&e[2]?(e[3].add(t),!0):!1},P=s=>{const t=v.get(s);t&&(--t[2],t[2]||(t[3].forEach(e=>e()),t[3].clear()),t[0].forEach(e=>{const{d:r}=e;s!==r&&P(r)}))},N=s=>{const{s:t,d:e}=s;let r=O.get(e);r||(r=[new Set],O.set(s.d,r)),r[0].add(s);let n=v.get(t);if(!n){const i=new Set,d=S(t,o=>{i.forEach(h=>{const{d:l,c:a,n:y,i:c}=h;t===l&&o.every(u=>u[1].length===1&&c.includes(u[1][0]))||h.p||(C(t,a),y?P(t):h.p=Promise.resolve().then(()=>{delete h.p,P(t)}))})},!0);n=[i,d,0,new Set],v.set(t,n)}n[0].add(s)},_=s=>{const{s:t,d:e}=s,r=O.get(e);r==null||r[0].delete(s),(r==null?void 0:r[0].size)===0&&O.delete(e);const n=v.get(t);if(n){const[i,d]=n;i.delete(s),i.size||(d(),v.delete(t))}},I=s=>{const t=O.get(s);return t?Array.from(t[0]):[]},Y=M("unstable_deriveSubscriptions",{add:N,remove:_,list:I});function J(s,t){const e=(t==null?void 0:t.proxy)||b({}),r=!!(t!=null&&t.sync),n=Object.keys(s);return n.forEach(i=>{if(Object.getOwnPropertyDescriptor(e,i))throw new Error("object property already defined");const d=s[i];let o=null;const h=()=>{if(o&&(Array.from(o).map(([c])=>U(c,h)).some(c=>c)||Array.from(o).every(([c,u])=>j(c)===u.v)))return;const l=new Map,a=d(c=>(l.set(c,{v:j(c)}),c)),y=()=>{l.forEach((c,u)=>{var E;const m=(E=o==null?void 0:o.get(u))==null?void 0:E.s;if(m)c.s=m;else{const w={s:u,d:e,k:i,c:h,n:r,i:n};N(w),c.s=w}}),o==null||o.forEach((c,u)=>{!l.has(u)&&c.s&&_(c.s)}),o=l};a instanceof Promise?a.finally(y):y(),e[i]=a};h()}),e}function L(s,t){const e=t!=null&&t.delete?new Set:null;I(s).forEach(r=>{const{k:n}=r;(!(t!=null&&t.keys)||t.keys.includes(n))&&(_(r),e&&e.add(n))}),e&&e.forEach(r=>{delete s[r]})}function K(s,t,e=s){const r={};return Object.keys(t).forEach(n=>{r[n]=i=>t[n](i(s))}),J(r,{proxy:e})}function V(s,t){Object.keys(t).forEach(r=>{if(Object.getOwnPropertyDescriptor(s,r))throw new Error("object property already defined");const n=t[r],{get:i,set:d}=typeof n=="function"?{get:n}:n,o={};o.get=()=>i(p(e)),d&&(o.set=h=>d(e,h)),Object.defineProperty(s,r,o)});const e=b(s);return e}const F=s=>typeof s=="object"&&s!==null;let A;const H=s=>{if(A||(A=k()[2]),!F(s)||A.has(s))return s;const t=Array.isArray(s)?[]:Object.create(Object.getPrototypeOf(s));return Reflect.ownKeys(s).forEach(e=>{t[e]=H(s[e])}),t};function X(s,t=!1){const e=b({value:s,history:D({wip:void 0,snapshots:[],index:-1}),clone:H,canUndo:()=>e.history.index>0,undo:()=>{e.canUndo()&&(e.value=e.history.wip=e.clone(e.history.snapshots[--e.history.index]))},canRedo:()=>e.history.index<e.history.snapshots.length-1,redo:()=>{e.canRedo()&&(e.value=e.history.wip=e.clone(e.history.snapshots[++e.history.index]))},saveHistory:()=>{e.history.snapshots.splice(e.history.index+1),e.history.snapshots.push(p(e).value),++e.history.index},subscribe:()=>S(e,r=>{r.every(n=>n[1][0]==="value"&&(n[0]!=="set"||n[2]!==e.history.wip))&&e.saveHistory()})});return e.saveHistory(),t||e.subscribe(),e}function $(s){const t=b({data:Array.from(new Set(s)),has(e){return this.data.indexOf(e)!==-1},add(e){let r=!1;return typeof e=="object"&&e!==null&&(r=this.data.indexOf(b(e))!==-1),this.data.indexOf(e)===-1&&!r&&this.data.push(e),this},delete(e){const r=this.data.indexOf(e);return r===-1?!1:(this.data.splice(r,1),!0)},clear(){this.data.splice(0)},get size(){return this.data.length},forEach(e){this.data.forEach(r=>{e(r,r,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 B(s){const t=b({data:Array.from(s||[]),has(e){return this.data.some(r=>r[0]===e)},set(e,r){const n=this.data.find(i=>i[0]===e);return n?n[1]=r:this.data.push([e,r]),this},get(e){var r;return(r=this.data.find(n=>n[0]===e))==null?void 0:r[1]},delete(e){const r=this.data.findIndex(n=>n[0]===e);return r===-1?!1:(this.data.splice(r,1),!0)},clear(){this.data.splice(0)},get size(){return this.data.length},toJSON(){return new Map(this.data)},forEach(e){this.data.forEach(r=>{e(r[1],r[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}}}}); |
@@ -0,5 +1,6 @@ | ||
type EnhancerOptions = Parameters<NonNullable<(typeof window)['__REDUX_DEVTOOLS_EXTENSION__']>['connect']>[0]; | ||
type Options = { | ||
enabled?: boolean; | ||
name?: string; | ||
}; | ||
} & EnhancerOptions; | ||
export declare function devtools<T extends object>(proxyObject: T, options?: Options): (() => void) | undefined; | ||
@@ -6,0 +7,0 @@ /** |
@@ -36,2 +36,3 @@ import { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
}; | ||
clone: <T>(obj: T) => T; | ||
canUndo: () => boolean; | ||
@@ -38,0 +39,0 @@ undo: () => void; |
@@ -0,5 +1,6 @@ | ||
type EnhancerOptions = Parameters<NonNullable<(typeof window)['__REDUX_DEVTOOLS_EXTENSION__']>['connect']>[0]; | ||
type Options = { | ||
enabled?: boolean; | ||
name?: string; | ||
}; | ||
} & EnhancerOptions; | ||
export declare function devtools<T extends object>(proxyObject: T, options?: Options): (() => void) | undefined; | ||
@@ -6,0 +7,0 @@ /** |
@@ -36,2 +36,3 @@ import { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
}; | ||
clone: <T>(obj: T) => T; | ||
canUndo: () => boolean; | ||
@@ -38,0 +39,0 @@ undo: () => void; |
@@ -77,2 +77,37 @@ (function (global, factory) { | ||
function _defineAccessor(type, obj, key, fn) { | ||
var desc = { | ||
configurable: !0, | ||
enumerable: !0 | ||
}; | ||
return desc[type] = fn, Object.defineProperty(obj, key, desc); | ||
} | ||
function _extends() { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
var _excluded = ["enabled", "name"]; | ||
var DEVTOOLS = Symbol(); | ||
@@ -89,3 +124,4 @@ function devtools(proxyObject, options) { | ||
_ref$name = _ref.name, | ||
name = _ref$name === void 0 ? '' : _ref$name; | ||
name = _ref$name === void 0 ? '' : _ref$name, | ||
rest = _objectWithoutPropertiesLoose(_ref, _excluded); | ||
var extension; | ||
@@ -102,5 +138,5 @@ try { | ||
var isTimeTraveling = false; | ||
var devtools = extension.connect({ | ||
var devtools = extension.connect(_extends({ | ||
name: name | ||
}); | ||
}, rest)); | ||
var unsub1 = vanilla.subscribe(proxyObject, function (ops) { | ||
@@ -431,4 +467,8 @@ var action = ops.filter(function (_ref2) { | ||
}; | ||
var refSet; | ||
var deepClone = function deepClone(obj) { | ||
if (!isObject(obj)) { | ||
if (!refSet) { | ||
refSet = vanilla.unstable_buildProxyFunction()[2]; | ||
} | ||
if (!isObject(obj) || refSet.has(obj)) { | ||
return obj; | ||
@@ -453,2 +493,3 @@ } | ||
}), | ||
clone: deepClone, | ||
canUndo: function canUndo() { | ||
@@ -459,3 +500,3 @@ return proxyObject.history.index > 0; | ||
if (proxyObject.canUndo()) { | ||
proxyObject.value = proxyObject.history.wip = deepClone(proxyObject.history.snapshots[--proxyObject.history.index]); | ||
proxyObject.value = proxyObject.history.wip = proxyObject.clone(proxyObject.history.snapshots[--proxyObject.history.index]); | ||
} | ||
@@ -468,3 +509,3 @@ }, | ||
if (proxyObject.canRedo()) { | ||
proxyObject.value = proxyObject.history.wip = deepClone(proxyObject.history.snapshots[++proxyObject.history.index]); | ||
proxyObject.value = proxyObject.history.wip = proxyObject.clone(proxyObject.history.snapshots[++proxyObject.history.index]); | ||
} | ||
@@ -494,10 +535,2 @@ }, | ||
function _defineAccessor(type, obj, key, fn) { | ||
var desc = { | ||
configurable: !0, | ||
enumerable: !0 | ||
}; | ||
return desc[type] = fn, Object.defineProperty(obj, key, desc); | ||
} | ||
function proxySet(initialValues) { | ||
@@ -504,0 +537,0 @@ var _proxy; |
@@ -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).valtioVanillaUtils={},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}})); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("valtio/vanilla")):"function"==typeof define&&define.amd?define(["exports","valtio/vanilla"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).valtioVanillaUtils={},t.valtioVanilla)}(this,(function(t,n){"use strict";var e;function r(t,n,e,r){var i={configurable:!0,enumerable:!0};return i[t]=r,Object.defineProperty(n,e,i)}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},i.apply(this,arguments)}var a=["enabled","name"],o=Symbol();var u=new WeakMap,s=new WeakMap,c=function t(n,e){var r=u.get(n);r&&(r[0].forEach((function(e){var r=e.d;n!==r&&t(r)})),++r[2],e&&r[3].add(e))},f=function(t,n){var e=u.get(t);return!(null==e||!e[2])&&(e[3].add(n),!0)},l=function t(n){var e=u.get(n);e&&(--e[2],e[2]||(e[3].forEach((function(t){return t()})),e[3].clear()),e[0].forEach((function(e){var r=e.d;n!==r&&t(r)})))},d=function(t){var e=t.s,r=t.d,i=s.get(r);i||(i=[new Set],s.set(t.d,i)),i[0].add(t);var a=u.get(e);if(!a){var o=new Set,f=n.subscribe(e,(function(t){o.forEach((function(n){var r=n.d,i=n.c,a=n.n,o=n.i;e===r&&t.every((function(t){return 1===t[1].length&&o.includes(t[1][0])}))||n.p||(c(e,i),a?l(e):n.p=Promise.resolve().then((function(){delete n.p,l(e)})))}))}),!0);a=[o,f,0,new Set],u.set(e,a)}a[0].add(t)},p=function(t){var n=t.s,e=t.d,r=s.get(e);null==r||r[0].delete(t),0===(null==r?void 0:r[0].size)&&s.delete(e);var i=u.get(n);if(i){var a=i[0],o=i[1];a.delete(t),a.size||(o(),u.delete(n))}},h=function(t){var n=s.get(t);return n?Array.from(n[0]):[]},v={add:d,remove:p,list:h};function y(t,e){var r=(null==e?void 0:e.proxy)||n.proxy({}),i=!(null==e||!e.sync),a=Object.keys(t);return a.forEach((function(e){if(Object.getOwnPropertyDescriptor(r,e))throw new Error("object property already defined");var o=t[e],u=null;!function t(){if(u){if(Array.from(u).map((function(n){var e=n[0];return f(e,t)})).some((function(t){return t})))return;if(Array.from(u).every((function(t){var e=t[0],r=t[1];return n.getVersion(e)===r.v})))return}var s=new Map,c=o((function(t){return s.set(t,{v:n.getVersion(t)}),t})),l=function(){var n;s.forEach((function(n,o){var s,c,f=null==(s=u)||null==(c=s.get(o))?void 0:c.s;if(f)n.s=f;else{var l={s:o,d:r,k:e,c:t,n:i,i:a};d(l),n.s=l}})),null==(n=u)||n.forEach((function(t,n){!s.has(n)&&t.s&&p(t.s)})),u=s};c instanceof Promise?c.finally(l):l(),r[e]=c}()})),r}var b,O=function t(e){if(b||(b=n.unstable_buildProxyFunction()[2]),"object"!=typeof(r=e)||null===r||b.has(e))return e;var r,i=Array.isArray(e)?[]:Object.create(Object.getPrototypeOf(e));return Reflect.ownKeys(e).forEach((function(n){i[n]=t(e[n])})),i};t.addComputed=function(t,n,e){void 0===e&&(e=t);var r={};return Object.keys(n).forEach((function(e){r[e]=function(r){return n[e](r(t))}})),y(r,{proxy:e})},t.derive=y,t.devtools=function(t,e){"string"==typeof e&&(console.warn("string name option is deprecated, use { name }. https://github.com/pmndrs/valtio/pull/400"),e={name:e});var r,u=e||{},s=u.enabled,c=u.name,f=void 0===c?"":c,l=function(t,n){if(null==t)return{};var e,r,i={},a=Object.keys(t);for(r=0;r<a.length;r++)e=a[r],n.indexOf(e)>=0||(i[e]=t[e]);return i}(u,a);try{r=null!=s&&s&&window.__REDUX_DEVTOOLS_EXTENSION__}catch(t){}if(r){var d=!1,p=r.connect(i({name:f},l)),h=n.subscribe(t,(function(e){var r=e.filter((function(t){return t[0],t[1][0]!==o})).map((function(t){return t[0]+":"+t[1].map(String).join(".")})).join(", ");if(r)if(d)d=!1;else{var i=Object.assign({},n.snapshot(t));delete i[o],p.send({type:r,updatedAt:(new Date).toLocaleString()},i)}})),v=p.subscribe((function(e){var r,i;if("ACTION"===e.type&&e.payload)try{Object.assign(t,JSON.parse(e.payload))}catch(t){console.error("please dispatch a serializable value that JSON.parse() and proxy() support\n",t)}if("DISPATCH"===e.type&&e.state){var a,u;if("JUMP_TO_ACTION"===(null==(a=e.payload)?void 0:a.type)||"JUMP_TO_STATE"===(null==(u=e.payload)?void 0:u.type)){d=!0;var s=JSON.parse(e.state);Object.assign(t,s)}t[o]=e}else if("DISPATCH"===e.type&&"COMMIT"===(null==(r=e.payload)?void 0:r.type))p.init(n.snapshot(t));else if("DISPATCH"===e.type&&"IMPORT_STATE"===(null==(i=e.payload)?void 0:i.type)){var c,f,l=null==(c=e.payload.nextLiftedState)?void 0:c.actionsById,h=(null==(f=e.payload.nextLiftedState)?void 0:f.computedStates)||[];d=!0,h.forEach((function(e,r){var i=e.state,a=l[r]||"No action found";Object.assign(t,i),0===r?p.init(n.snapshot(t)):p.send(a,n.snapshot(t))}))}}));return p.init(n.snapshot(t)),function(){h(),null==v||v()}}},t.proxyMap=function(t){var e,i=n.proxy((r("get",e={data:Array.from(t||[]),has:function(t){return this.data.some((function(n){return n[0]===t}))},set:function(t,n){var e=this.data.find((function(n){return n[0]===t}));return e?e[1]=n:this.data.push([t,n]),this},get:function(t){var n;return null==(n=this.data.find((function(n){return n[0]===t})))?void 0:n[1]},delete:function(t){var n=this.data.findIndex((function(n){return n[0]===t}));return-1!==n&&(this.data.splice(n,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 n=this;this.data.forEach((function(e){t(e[1],e[0],n)}))},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"})),e[Symbol.iterator]=function(){return this.entries()},e));return Object.defineProperties(i,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(i),i},t.proxySet=function(t){var e,i=n.proxy((r("get",e={data:Array.from(new Set(t)),has:function(t){return-1!==this.data.indexOf(t)},add:function(t){var e=!1;return"object"==typeof t&&null!==t&&(e=-1!==this.data.indexOf(n.proxy(t))),-1!==this.data.indexOf(t)||e||this.data.push(t),this},delete:function(t){var n=this.data.indexOf(t);return-1!==n&&(this.data.splice(n,1),!0)},clear:function(){this.data.splice(0)},get size(){return this.data.length},forEach:function(t){var n=this;this.data.forEach((function(e){t(e,e,n)}))}},Symbol.toStringTag,(function(){return"Set"})),e.toJSON=function(){return new Set(this.data)},e[Symbol.iterator]=function(){return this.data[Symbol.iterator]()},e.values=function(){return this.data.values()},e.keys=function(){return this.data.values()},e.entries=function(){return new Set(this.data).entries()},e));return Object.defineProperties(i,{data:{enumerable:!1},size:{enumerable:!1},toJSON:{enumerable:!1}}),Object.seal(i),i},t.proxyWithComputed=function(t,e){Object.keys(e).forEach((function(i){if(Object.getOwnPropertyDescriptor(t,i))throw new Error("object property already defined");var a=e[i],o="function"==typeof a?{get:a}:a,u=o.get,s=o.set,c={get:function(){return u(n.snapshot(r))}};s&&(c.set=function(t){return s(r,t)}),Object.defineProperty(t,i,c)}));var r=n.proxy(t);return r},t.proxyWithHistory=function(t,e){void 0===e&&(e=!1);var r=n.proxy({value:t,history:n.ref({wip:void 0,snapshots:[],index:-1}),clone:O,canUndo:function(){return r.history.index>0},undo:function(){r.canUndo()&&(r.value=r.history.wip=r.clone(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=r.clone(r.history.snapshots[++r.history.index]))},saveHistory:function(){r.history.snapshots.splice(r.history.index+1),r.history.snapshots.push(n.snapshot(r).value),++r.history.index},subscribe:function(){return n.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(),e||r.subscribe(),r},t.subscribeKey=function(t,e,r,i){var a=t[e];return n.subscribe(t,(function(){var n=t[e];Object.is(a,n)||r(a=n)}),i)},t.underive=function(t,n){var e=null!=n&&n.delete?new Set:null;h(t).forEach((function(t){var r=t.k;null!=n&&n.keys&&!n.keys.includes(r)||(p(t),e&&e.add(r))})),e&&e.forEach((function(n){delete t[n]}))},t.unstable_deriveSubscriptions=v,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 e&&e.add(u),function u(){if(i){a.forEach((function(t){return t()})),a.clear();var s=new Set,c=e;e=a;try{var f=t((function(t){return s.add(t),t}));f&&a.add(f)}finally{e=c}o.forEach((function(t,n){s.has(n)?s.delete(n):(o.delete(n),t())})),s.forEach((function(t){var e=n.subscribe(t,u,null==r?void 0:r.sync);o.set(t,e)}))}}(),u}})); |
@@ -75,2 +75,37 @@ 'use strict'; | ||
function _defineAccessor(type, obj, key, fn) { | ||
var desc = { | ||
configurable: !0, | ||
enumerable: !0 | ||
}; | ||
return desc[type] = fn, Object.defineProperty(obj, key, desc); | ||
} | ||
function _extends() { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
var _excluded = ["enabled", "name"]; | ||
var DEVTOOLS = Symbol(); | ||
@@ -87,3 +122,4 @@ function devtools(proxyObject, options) { | ||
_ref$name = _ref.name, | ||
name = _ref$name === void 0 ? '' : _ref$name; | ||
name = _ref$name === void 0 ? '' : _ref$name, | ||
rest = _objectWithoutPropertiesLoose(_ref, _excluded); | ||
var extension; | ||
@@ -100,5 +136,5 @@ try { | ||
var isTimeTraveling = false; | ||
var devtools = extension.connect({ | ||
var devtools = extension.connect(_extends({ | ||
name: name | ||
}); | ||
}, rest)); | ||
var unsub1 = vanilla.subscribe(proxyObject, function (ops) { | ||
@@ -429,4 +465,8 @@ var action = ops.filter(function (_ref2) { | ||
}; | ||
var refSet; | ||
var deepClone = function deepClone(obj) { | ||
if (!isObject(obj)) { | ||
if (!refSet) { | ||
refSet = vanilla.unstable_buildProxyFunction()[2]; | ||
} | ||
if (!isObject(obj) || refSet.has(obj)) { | ||
return obj; | ||
@@ -451,2 +491,3 @@ } | ||
}), | ||
clone: deepClone, | ||
canUndo: function canUndo() { | ||
@@ -457,3 +498,3 @@ return proxyObject.history.index > 0; | ||
if (proxyObject.canUndo()) { | ||
proxyObject.value = proxyObject.history.wip = deepClone(proxyObject.history.snapshots[--proxyObject.history.index]); | ||
proxyObject.value = proxyObject.history.wip = proxyObject.clone(proxyObject.history.snapshots[--proxyObject.history.index]); | ||
} | ||
@@ -466,3 +507,3 @@ }, | ||
if (proxyObject.canRedo()) { | ||
proxyObject.value = proxyObject.history.wip = deepClone(proxyObject.history.snapshots[++proxyObject.history.index]); | ||
proxyObject.value = proxyObject.history.wip = proxyObject.clone(proxyObject.history.snapshots[++proxyObject.history.index]); | ||
} | ||
@@ -492,10 +533,2 @@ }, | ||
function _defineAccessor(type, obj, key, fn) { | ||
var desc = { | ||
configurable: !0, | ||
enumerable: !0 | ||
}; | ||
return desc[type] = fn, Object.defineProperty(obj, key, desc); | ||
} | ||
function proxySet(initialValues) { | ||
@@ -502,0 +535,0 @@ var _proxy; |
@@ -0,5 +1,6 @@ | ||
type EnhancerOptions = Parameters<NonNullable<(typeof window)['__REDUX_DEVTOOLS_EXTENSION__']>['connect']>[0]; | ||
type Options = { | ||
enabled?: boolean; | ||
name?: string; | ||
}; | ||
} & EnhancerOptions; | ||
export declare function devtools<T extends object>(proxyObject: T, options?: Options): (() => void) | undefined; | ||
@@ -6,0 +7,0 @@ /** |
@@ -36,2 +36,3 @@ import type { INTERNAL_Snapshot as Snapshot } from 'valtio/vanilla'; | ||
}; | ||
clone: <T>(obj: T) => T; | ||
canUndo: () => boolean; | ||
@@ -38,0 +39,0 @@ undo: () => void; |
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
319504
7534