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

feat: Add ES6 Sets support #358

Closed
wants to merge 27 commits into from
Closed

Conversation

@aigoncharov
Copy link
Contributor

@aigoncharov aigoncharov commented Apr 22, 2019

No description provided.

@aigoncharov
Copy link
Contributor Author

@aigoncharov aigoncharov commented Apr 22, 2019

This one doesn't have patch-related functionality yet. Will work on it as soon as I have some free time. However, I believe we could merge it in and have one extra PR with patches for Sets opened later.

Copy link
Collaborator

@aleclarson aleclarson left a comment

Nice work! 🎉

src/common.js Outdated Show resolved Hide resolved
: Reflect.get(state, prop, receiver)
},
ownKeys(state) {
return Reflect.ownKeys(source(state))

This comment has been minimized.

@aleclarson

aleclarson Apr 22, 2019
Collaborator

This trap can be removed

This comment has been minimized.

@aigoncharov

aigoncharov Apr 22, 2019
Author Contributor

Wouldn't it return keys of our state then?

This comment has been minimized.

@aleclarson

aleclarson Apr 22, 2019
Collaborator

Good catch. 👍 I remember adding this trap to fix an internal issue, then removing it once realizing it's not necessary to fix the internals. I didn't think of users calling Object.keys on their Set/Map objects, which definitely shouldn't return the keys of the draft-state.

This comment has been minimized.

@aleclarson

aleclarson Apr 22, 2019
Collaborator

If we care about the Object.keys edge case, we should also support Object.getOwnPropertyDescriptor by adding a getOwnPropertyDescriptor trap.

This comment has been minimized.

@aleclarson

aleclarson Apr 22, 2019
Collaborator

And what about the getPrototypeOf or setPrototypeOf traps? And the defineProperty, set, deleteProperty traps? It gets to be a bit much, but for the sake of correctness, we should probably do it?

This comment has been minimized.

@aigoncharov

aigoncharov Apr 22, 2019
Author Contributor

I guess we're gonna need tests to cover them as well.

src/proxy.js Outdated Show resolved Hide resolved
src/proxy.js Outdated Show resolved Hide resolved
src/proxy.js Show resolved Hide resolved
src/proxy.js Show resolved Hide resolved
@aigoncharov
Copy link
Contributor Author

@aigoncharov aigoncharov commented Apr 22, 2019

@aleclarson addressed your comments: either made a corresponding change or replied in a thread.

@aigoncharov
Copy link
Contributor Author

@aigoncharov aigoncharov commented Apr 22, 2019

Added patch-related functionality for ES6 Sets.

Items to discuss:

  1. Patches for Maps will work only for string and numeric keys. Is it ok? Should we add a section to README only or have an exception thrown?
  2. I'm not sure how compatible with RFC-6902 JSON patch standard is this record for ES6 Set patches. Currently, these patches cannot be applied in a different order.
  3. Do we really-really-really want to support ES5? :)

TODOs:

  • Typings
  • Add tests (and most probably add missing implementation) for onDelete and onAssign hooks for cases with ES6 Maps and ES6 Sets

@aleclarson if you merge it to v4 branch, I'd be happy to carry on this discussion there, since it really does belong there.

@aleclarson
Copy link
Collaborator

@aleclarson aleclarson commented Apr 22, 2019

  1. Patches for Maps will work only for string and numeric keys. Is it ok? Should we add a section to README only or have an exception thrown?

No, we should make sure changes to object keys have patches created for them, since Immer patches can be useful even when not serialized to JSON.

Note: Immer prefers working with tree-like data structures, and I'm not sure what the bugs are when relational data is used.

2. I'm not sure how compatible with RFC-6902 JSON patch standard is this record for ES6 Set patches. Currently, these patches cannot be applied in a different order.

To be clear, Immer patches aren't strictly JSON patches, but you must use JSON-only keys/values if you ever need to serialize the patches.

3. Do we really-really-really want to support ES5? :)

To not support ES5 would add unwanted complexity to the API for ES5 users. :(

@aleclarson aleclarson force-pushed the immerjs:v4 branch 2 times, most recently from 5e6dcf8 to c90cd57 Apr 23, 2019
@aleclarson
Copy link
Collaborator

@aleclarson aleclarson commented Apr 23, 2019

Merged into the v4 branch

@aleclarson aleclarson closed this Apr 23, 2019
@aleclarson aleclarson mentioned this pull request Apr 23, 2019
13 of 13 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.