Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this an expected behavior of proxyMap #12

Closed
dai-shi opened this issue Feb 22, 2019 · 3 comments
Closed

Is this an expected behavior of proxyMap #12

dai-shi opened this issue Feb 22, 2019 · 3 comments

Comments

@dai-shi
Copy link
Collaborator

dai-shi commented Feb 22, 2019

Hi, I'm trying to improve https:/dai-shi/react-hooks-easy-redux with proxyMap,
but it doesn't behave as I expect. Do I misunderstand the usage?

$ node 
> const { proxyState } = require('proxyequal')
undefined
> const proxyMap = new WeakMap()
undefined
> const state = { a: 1, b: 2 }
undefined
> const trapped1 = proxyState(state, null, proxyMap)
undefined
> trapped1.state.a
1
> trapped1.affected
[ '.a' ]
> const trapped2 = proxyState(state, null, proxyMap)
undefined
> trapped2.state.b
2
> trapped2.affected
[]
> trapped1.affected
[ '.a', '.b' ]

I was expecting trapped2.affected to be ['.b'] and trapped1.affected to be kept ['.a'].

@theKashey
Copy link
Owner

Yeah. It should be this way, and should not.

 state = { a, b }
 // it should maintain ref equality
 newState.a === oldState.b

So a would be the same Proxy for both instances. That should be that way.
And it would have callbacks, defined for the first use, not the second. That should not be that way.

It's a bit complicated, but one have to return the same objects, with a different setup. And I am not sure it is possible.

To be more concrete - for this case it is possible - push "path" on component access, and pop it just after. So.any.deep.property access would work.

Once you store variable somewhere const {a:oldA}=oldState; const {a: newA } = newState - information is lost.

Probably:

  1. Push/pop the right accesser on access.
  2. Update all active proxies on unprefixed access.

Look like .2 would fix the current buggy behaviour, then you lose the track, and .1 would make tracking more accurate.

PS: Thank you for an issue.

@dai-shi
Copy link
Collaborator Author

dai-shi commented Feb 24, 2019

Complicated... but I understand the object identity.
Let me try caching trapped in the front.
Thanks!

@dai-shi dai-shi closed this as completed Feb 24, 2019
@dai-shi
Copy link
Collaborator Author

dai-shi commented Feb 25, 2019

Here's what I did: dai-shi/reactive-react-redux@23e2c5a

The benchmark result seems good: dai-shi/reactive-react-redux#3 (comment)

dai-shi referenced this issue in dai-shi/reactive-react-redux Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants