Skip to content

Commit 077564c

Browse files
committed
Avoid extending Promise.
1 parent 1be5794 commit 077564c

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

packages/react-async/src/reducer.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import { getInitialStatus, getIdleStatus, getStatusProps, statusTypes } from "./status"
22

33
// This exists to make sure we don't hold any references to user-provided functions
4-
class NeverSettle extends Promise {
5-
constructor() {
6-
super(() => {}, () => {})
7-
/* istanbul ignore next */
8-
if (Object.setPrototypeOf) {
9-
// Not available in IE 10, but can be polyfilled
10-
Object.setPrototypeOf(this, NeverSettle.prototype)
11-
}
12-
}
4+
function NeverSettle() {}
5+
/* istanbul ignore next */
6+
if (Object.setPrototypeOf) {
7+
// Not available in IE 10, but can be polyfilled
8+
Object.setPrototypeOf(NeverSettle, Promise)
9+
}
10+
NeverSettle.prototype = Object.assign(Object.create(Promise.prototype), {
1311
finally() {
1412
return this
15-
}
13+
},
1614
catch() {
1715
return this
18-
}
16+
},
1917
then() {
2018
return this
21-
}
22-
}
19+
},
20+
})
2321

2422
export const neverSettle = new NeverSettle()
2523

0 commit comments

Comments
 (0)