Comparing version 0.5.0 to 0.5.1
@@ -340,8 +340,5 @@ 'use strict'; | ||
var lastSnapshot = react.useRef(); | ||
if (!lastSnapshot.current) { | ||
// lazy initialization | ||
useIsomorphicLayoutEffect(function () { | ||
lastSnapshot.current = prevSnapshot.current = snapshot(p); | ||
} | ||
}, [p]); | ||
useIsomorphicLayoutEffect(function () { | ||
@@ -356,21 +353,18 @@ lastAffected.current = affected; | ||
var notifyInSync = options == null ? void 0 : options.sync; | ||
var sub = react.useMemo(function () { | ||
var deepChangedCache = new WeakMap(); | ||
return function (p, cb) { | ||
return subscribe(p, function () { | ||
var nextSnapshot = snapshot(p); | ||
lastSnapshot.current = nextSnapshot; | ||
var sub = react.useCallback(function (p, cb) { | ||
return subscribe(p, function () { | ||
var nextSnapshot = snapshot(p); | ||
lastSnapshot.current = nextSnapshot; | ||
try { | ||
if (lastAffected.current && !proxyCompare.isDeepChanged(prevSnapshot.current, nextSnapshot, lastAffected.current, deepChangedCache)) { | ||
// not changed | ||
return; | ||
} | ||
} catch (e) {// ignore if a promise or something is thrown | ||
try { | ||
if (lastAffected.current && !proxyCompare.isDeepChanged(prevSnapshot.current, nextSnapshot, lastAffected.current, new WeakMap())) { | ||
// not changed | ||
return; | ||
} | ||
} catch (e) {// ignore if a promise or something is thrown | ||
} | ||
prevSnapshot.current = nextSnapshot; | ||
cb(); | ||
}, notifyInSync); | ||
}; | ||
prevSnapshot.current = nextSnapshot; | ||
cb(); | ||
}, notifyInSync); | ||
}, [notifyInSync]); | ||
@@ -377,0 +371,0 @@ var currSnapshot = useMutableSource(getMutableSource(p), snapshot, sub); |
@@ -336,8 +336,5 @@ var valtio = (function (exports, react, proxyCompare) { | ||
var lastSnapshot = react.useRef(); | ||
if (!lastSnapshot.current) { | ||
// lazy initialization | ||
useIsomorphicLayoutEffect(function () { | ||
lastSnapshot.current = prevSnapshot.current = snapshot(p); | ||
} | ||
}, [p]); | ||
useIsomorphicLayoutEffect(function () { | ||
@@ -352,21 +349,18 @@ lastAffected.current = affected; | ||
var notifyInSync = options == null ? void 0 : options.sync; | ||
var sub = react.useMemo(function () { | ||
var deepChangedCache = new WeakMap(); | ||
return function (p, cb) { | ||
return subscribe(p, function () { | ||
var nextSnapshot = snapshot(p); | ||
lastSnapshot.current = nextSnapshot; | ||
var sub = react.useCallback(function (p, cb) { | ||
return subscribe(p, function () { | ||
var nextSnapshot = snapshot(p); | ||
lastSnapshot.current = nextSnapshot; | ||
try { | ||
if (lastAffected.current && !proxyCompare.isDeepChanged(prevSnapshot.current, nextSnapshot, lastAffected.current, deepChangedCache)) { | ||
// not changed | ||
return; | ||
} | ||
} catch (e) {// ignore if a promise or something is thrown | ||
try { | ||
if (lastAffected.current && !proxyCompare.isDeepChanged(prevSnapshot.current, nextSnapshot, lastAffected.current, new WeakMap())) { | ||
// not changed | ||
return; | ||
} | ||
} catch (e) {// ignore if a promise or something is thrown | ||
} | ||
prevSnapshot.current = nextSnapshot; | ||
cb(); | ||
}, notifyInSync); | ||
}; | ||
prevSnapshot.current = nextSnapshot; | ||
cb(); | ||
}, notifyInSync); | ||
}, [notifyInSync]); | ||
@@ -373,0 +367,0 @@ var currSnapshot = useMutableSource(getMutableSource(p), snapshot, sub); |
36
index.js
@@ -1,2 +0,2 @@ | ||
import { useRef, useState, useEffect, useReducer, useMemo, useLayoutEffect, useDebugValue } from 'react'; | ||
import { useRef, useState, useEffect, useReducer, useCallback, useMemo, useLayoutEffect, useDebugValue } from 'react'; | ||
import { markToTrack, getUntrackedObject, isDeepChanged, createDeepProxy, affectedToPathList } from 'proxy-compare'; | ||
@@ -320,8 +320,5 @@ | ||
const lastSnapshot = useRef(); | ||
if (!lastSnapshot.current) { | ||
// lazy initialization | ||
useIsomorphicLayoutEffect(() => { | ||
lastSnapshot.current = prevSnapshot.current = snapshot(p); | ||
} | ||
}, [p]); | ||
useIsomorphicLayoutEffect(() => { | ||
@@ -336,20 +333,17 @@ lastAffected.current = affected; | ||
const notifyInSync = options == null ? void 0 : options.sync; | ||
const sub = useMemo(() => { | ||
const deepChangedCache = new WeakMap(); | ||
return (p, cb) => subscribe(p, () => { | ||
const nextSnapshot = snapshot(p); | ||
lastSnapshot.current = nextSnapshot; | ||
const sub = useCallback((p, cb) => subscribe(p, () => { | ||
const nextSnapshot = snapshot(p); | ||
lastSnapshot.current = nextSnapshot; | ||
try { | ||
if (lastAffected.current && !isDeepChanged(prevSnapshot.current, nextSnapshot, lastAffected.current, deepChangedCache)) { | ||
// not changed | ||
return; | ||
} | ||
} catch (e) {// ignore if a promise or something is thrown | ||
try { | ||
if (lastAffected.current && !isDeepChanged(prevSnapshot.current, nextSnapshot, lastAffected.current, new WeakMap())) { | ||
// not changed | ||
return; | ||
} | ||
} catch (e) {// ignore if a promise or something is thrown | ||
} | ||
prevSnapshot.current = nextSnapshot; | ||
cb(); | ||
}, notifyInSync); | ||
}, [notifyInSync]); | ||
prevSnapshot.current = nextSnapshot; | ||
cb(); | ||
}, notifyInSync), [notifyInSync]); | ||
const currSnapshot = useMutableSource(getMutableSource(p), snapshot, sub); | ||
@@ -356,0 +350,0 @@ |
{ | ||
"name": "valtio", | ||
"private": false, | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "💊 Valtio makes proxy-state simple for React and Vanilla", | ||
@@ -6,0 +6,0 @@ "main": "index.cjs.js", |
@@ -1,2 +0,4 @@ | ||
![VALTIO](valtio.svg) | ||
<img src="logo.svg"> | ||
<br /> | ||
<br/> | ||
@@ -3,0 +5,0 @@ <code>npm i valtio</code> makes proxy-state simple |
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
148
61091
1593