Supporting of new Set methods in observable Sets
inoyakaigor opened this issue · comments
Intended outcome:
According to a New Set methods proposal a Set class will have a bunch of new methods (more on MDN). This proposal currently at Stage 3 therefore it means it is becoming part of ECMAScript standart
Current browser's support
Method | Firefox (Nigthly) | Chrome (> 122) | Safari (> 17) |
---|---|---|---|
intersection | ⏳ | ✔️ | ✔️ |
union | ⏳ | ✔️ | ✔️ |
difference | ⏳ | ✔️ | ✔️ |
symmetricDifference | ⏳ | ✔️ | ✔️ |
isSubsetOf | ⏳ | ✔️ | ✔️ |
isSupersetOf | ⏳ | ✔️ | ✔️ |
isDisjointFrom | ⏳ | ✔️ | ✔️ |
I've created a sandbox with example of code that includes two Sets as store's fields. One of them is observable other one is not.
Actual outcome:
For example if log a store.reactiveSet.intersection
we will see an undefined
in the console. If log a store.nonReactiveSet.intersection
we will see a nonReactiveSet ƒ symmetricDifference() { [native code] }
(there I used Chrome 123)
Obviously for other Set's methods result is the same:
How to reproduce the issue:
Run code from provided sandbox. Look into browser's console
Versions
Mobx 6.12.1
Also I propose made this as part of Mobx 7 roadmap #3796
Also I think there is only one place for changes that will add support the new methods: mobx/src/types/observableset.ts and it means it is not a big deal but can't imagine what exactly future code should look like?
Great idea. PR welcome. In many cases these kind of operations can be implemented by calling the original version on the Set prototype with iterator of the observable set.
Also I just realised that there also should be added Object.groupBy and Map.groupBy