Skip to content
This repository was archived by the owner on May 15, 2019. It is now read-only.

Commit 5a8ffdc

Browse files
committed
Don't use deprecated isMounted anymore
Summary: Even though this is a mixin, which is already pretty darn deprecated, the new `create-react-class` package gives //extra// warnings about calling `this.isMounted()`. In this change, we remove `this.isMounted()` from `BackboneMixin`, and reimplement mount state ourselves. This is just as bad, but is a quick way of suppressing the error message that's crashing my unit tests :/ Test Plan: In the Khan Academy webapp: ``` tools/tsm-2017-js-codemods/upgrade_js.py javascript/projectfeedback-package/projectfeedback-form.jsx tools/runjstests.py javascript/projectfeedback-package/projectfeedback-form_test.jsx ``` Before this change, this test fails, with a "isMounted is deprecated" error message. After this change, this test passes. Auditors: john
1 parent fee9ceb commit 5a8ffdc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

js/backbone-mixin.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,20 @@
2626
* This binds *and* unbinds the events.
2727
*/
2828
const BackboneMixin = {
29+
_isMounted: false,
30+
2931
componentDidMount: function() {
32+
this._isMounted = true;
33+
3034
this._backboneModels = this.getBackboneModels();
3135
this._validateModelArray(this._backboneModels);
3236

3337
this._bind(this._backboneModels);
3438
},
3539

3640
componentWillUnmount: function() {
41+
this._isMounted = false;
42+
3743
this._unbind(this._backboneModels);
3844
},
3945

@@ -79,7 +85,7 @@ const BackboneMixin = {
7985
// TODO(joel): more rigorous fix needed? -- for the following error:
8086
// "Invariant Violation: forceUpdate(...): Can only force an update on
8187
// mounted or mounting components."
82-
if (this.isMounted()) {
88+
if (this._isMounted) {
8389
this.forceUpdate();
8490
}
8591
},

0 commit comments

Comments
 (0)