Skip to content

Avoid extending built-in JS classes #175

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

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Avoid extending Promise.
  • Loading branch information
ghengeveld committed Oct 10, 2019
commit 077564cd794a8526e6c9f48286b54f0acf562d71
24 changes: 11 additions & 13 deletions packages/react-async/src/reducer.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { getInitialStatus, getIdleStatus, getStatusProps, statusTypes } from "./status"

// This exists to make sure we don't hold any references to user-provided functions
class NeverSettle extends Promise {
constructor() {
super(() => {}, () => {})
/* istanbul ignore next */
if (Object.setPrototypeOf) {
// Not available in IE 10, but can be polyfilled
Object.setPrototypeOf(this, NeverSettle.prototype)
}
}
function NeverSettle() {}
/* istanbul ignore next */
if (Object.setPrototypeOf) {
// Not available in IE 10, but can be polyfilled
Object.setPrototypeOf(NeverSettle, Promise)
}
NeverSettle.prototype = Object.assign(Object.create(Promise.prototype), {
finally() {
return this
}
},
catch() {
return this
}
},
then() {
return this
}
}
},
})

export const neverSettle = new NeverSettle()

Expand Down