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

WIP: Support for Maps and Sets #149

Closed
wants to merge 8 commits into from

Conversation

RikuVan
Copy link

@RikuVan RikuVan commented May 5, 2018

I had a go at this for learnings sake, but I am pretty unsure if this was the way to go about it. I didn't see the benefit in using a real 'Proxy' since all mutations go through the methods. This does not support WeakMap and WeakSet (i have my doubts it is really worth it as you cannot clone them in the same way you can Maps and Sets).

@coveralls
Copy link

coveralls commented May 5, 2018

Coverage Status

Coverage increased (+1.1%) to 94.231% when pulling 6de8e9e on RikuVan:support_map_and_set into 84229e2 on mweststrate:master.

@RikuVan
Copy link
Author

RikuVan commented May 6, 2018

ok the es5 part is not working correctly. Will try to look again at it when I have time.

@RikuVan RikuVan closed this May 6, 2018
@RikuVan RikuVan reopened this May 6, 2018
@RikuVan
Copy link
Author

RikuVan commented May 6, 2018

The main problem I am having in es5 after add the Map and Set proxy is that array operations are affected--so push and pop result in undefined value. I will add an example failing test. Would thankful if someone could give me a tip about how the added code could affect arrays.

@RikuVan
Copy link
Author

RikuVan commented May 6, 2018

Well that is weird. I can't seem to write a failing test with the array problem I described 🤔 so maybe something with how I am using Immer locally.

@RikuVan RikuVan force-pushed the support_map_and_set branch from 74c697e to 97dae3a Compare May 7, 2018 17:18
@RikuVan RikuVan force-pushed the support_map_and_set branch from 97dae3a to 6de8e9e Compare May 7, 2018 17:54
@mweststrate
Copy link
Collaborator

Thanks a lot! Will be travelling next week and will review in detail afterwards, but looking promising so far!

@RikuVan
Copy link
Author

RikuVan commented May 25, 2018

Been meaning to come back to this for some time as I never really addressed the nested Map/Sets possibility. I have not written tests or really looked at this at all, but I am sure the current code doesn't work for nested Maps/Set updates, like Map.get("a").get("b").add(10). But i thought to look at this on the weekend, or at least write some failing tests.

@mweststrate
Copy link
Collaborator

Ok, thanks in advance!

@mweststrate mweststrate changed the title Support for Maps and Sets WIP: Support for Maps and Sets May 28, 2018
@mweststrate
Copy link
Collaborator

N.B. if you are stuck with the implementation somewhere just let me know, but having full test coverage is super useful already!

@RikuVan
Copy link
Author

RikuVan commented May 29, 2018

Yeah, I spent a number of hours the last week playing with this and could not get nested Maps and Sets to be correctly cloned. I tried, for example, recursively proxying all the nested Maps and Sets initially. This mostly seems to work, although it caused a few es5 tests to fail. But it doesn't result in the new test passing. I don't really get why the copying fails to result in new objects. I logged out e.g. old Set and new Set and they are different after being marked as changed. But somehow this is overwritten by the old version--maybe by a parent. I also tried a completely different approach, just tracking all the Maps and Sets in a WeakMap and then doing deep comparisons to see if something should be copied. But this resulted in a crap load of code and a lot of indirection, plus probably horrible performance if there are lots of Maps. I don't think that is the way to go. So, yeah, kind of stuck.

It is perhaps also good just to clarify what the goal is. I presumed that there should be structural sharing, which I understand to mean that only nested Maps/Sets with changes should be copied. But perhaps it would be easier to achieve if the idea was that however deep the update, everything inside that root Map or Set would be copied by the parent--so really the parent just needs a signal from a chlld that it changed rather than the chain of updates down to the parent. If that makes any sense...

@RikuVan
Copy link
Author

RikuVan commented Aug 31, 2018

Hi, I am going to close this PR, which I have not worked on since I did it. It was interesting exercise to try this but I didn't really see a clear way forward after my initial attempts.

@RikuVan RikuVan closed this Aug 31, 2018
Copy link

@samuelamars samuelamars left a comment

Choose a reason for hiding this comment

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

?????

Copy link

@samuelamars samuelamars left a comment

Choose a reason for hiding this comment

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

Maybe

Copy link

@samuelamars samuelamars left a comment

Choose a reason for hiding this comment

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

Good

@mweststrate mweststrate mentioned this pull request Apr 18, 2019
mweststrate added a commit that referenced this pull request Apr 18, 2019
@mweststrate mweststrate mentioned this pull request Apr 18, 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

Successfully merging this pull request may close these issues.

4 participants