Skip to content

Commit

Permalink
3850 - call a method on the argument
Browse files Browse the repository at this point in the history
  • Loading branch information
inoyakaigor committed Apr 15, 2024
1 parent eabcdde commit 9763039
Show file tree
Hide file tree
Showing 4 changed files with 1,813 additions and 1,818 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -68,7 +68,7 @@
"tape": "^5.0.1",
"ts-jest": "^29.0.5",
"tsdx": "^0.14.1",
"typescript": "^5.0.2"
"typescript": "^5.5.0-dev.20240415"
},
"husky": {
"hooks": {
Expand Down
17 changes: 17 additions & 0 deletions packages/mobx/src/global.d.ts
@@ -1 +1,18 @@
declare const __DEV__: boolean

// This code is a copy from TS PR#57230
// Should be removed after it merged
interface ReadonlySetLike<T> {
/**
* Despite its name, returns an iterable of the values in the set-like.
*/
keys(): Iterable<T>
/**
* @returns a boolean indicating whether an element with the specified value exists in the set-like or not.
*/
has(value: T): boolean
/**
* @returns the number of (unique) elements in the set-like.
*/
readonly size: number
}
14 changes: 11 additions & 3 deletions packages/mobx/src/types/observableset.ts
Expand Up @@ -243,12 +243,20 @@ export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillCh
} as any)
}

intersection(otherSet: Set<T>): IterableIterator<T> {
intersection<U>(otherSet: ReadonlySetLike<U>): IterableIterator<T & U> {
this.atom_.reportObserved()
const self = this
let nextIndex = 0
const observableValues = Array.from(this.data_.intersection(otherSet))
return makeIterable<T>({

let observableValues
if (typeof otherSet.intersection !== "function") {
observableValues = Array.from(otherSet.intersection(this.data_))
} else {
const dehancedSet = new Set(this)
observableValues = Array.from(dehancedSet.intersection(otherSet))
}

return makeIterable<T & U>({
next() {
return nextIndex < observableValues.length
? { value: self.dehanceValue_(observableValues[nextIndex++]), done: false }
Expand Down

0 comments on commit 9763039

Please sign in to comment.