Skip to content

Commit

Permalink
fix(utils): revert subscribeKey impl to the original one (without ops) (
Browse files Browse the repository at this point in the history
#554)

* Add test for subscribeKey and proxyWithComputed

* refactor test

* revert subscribeKey with old impl

Co-authored-by: Luke Barlow <[email protected]>
  • Loading branch information
dai-shi and lukebarlow authored Oct 7, 2022
1 parent 6e58c9d commit fc12e01
Show file tree
Hide file tree
Showing 2 changed files with 271 additions and 247 deletions.
8 changes: 5 additions & 3 deletions src/utils/subscribeKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export function subscribeKey<T extends object, K extends keyof T>(
callback: (value: T[K]) => void,
notifyInSync?: boolean
) {
let prevValue = proxyObject[key]
return subscribe(
proxyObject,
(ops) => {
if (ops.some((op) => op[1][0] === key)) {
callback(proxyObject[key])
() => {
const nextValue = proxyObject[key]
if (!Object.is(prevValue, nextValue)) {
callback((prevValue = nextValue))
}
},
notifyInSync
Expand Down
Loading

1 comment on commit fc12e01

@vercel
Copy link

@vercel vercel bot commented on fc12e01 Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

valtio – ./

valtio-pmndrs.vercel.app
valtio-git-main-pmndrs.vercel.app
valtio.vercel.app
valtio.pmnd.rs

Please sign in to comment.