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

Commit 24e4194

Browse files
committed
Whoops, rename _isMounted to _backboneMixinIsMounted, to avoid conflicts
Summary: Oops, in my last commit, I added an `_isMounted` property to the `BackboneMixin`. Unfortunately, this isn't a super unique name, and some components that use `BackboneMixin` define their //own// `_isMounted` property. `createReactClass` considers this to be an error. In this change, I rename `BackboneMixin`'s mount-tracking property to `_backboneMixinIsMounted`, to avoid conflicts with other components or mixins. Test Plan: In Khan Academy's webapp: ``` tools/tsm-2017-js-codemods/upgrade_js.py tools/runjstests.py ``` Before this change, this would trigger an error in some dashboard and profile components, warning that the property `_isMounted` is being defined twice. After this change, all tests pass. Auditors: john
1 parent 5a8ffdc commit 24e4194

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

js/backbone-mixin.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@
2626
* This binds *and* unbinds the events.
2727
*/
2828
const BackboneMixin = {
29-
_isMounted: false,
29+
// This is just us re-implementing `isMounted()`, to avoid noisy
30+
// deprecation warnings. We give it a unique prefixed name, to avoid
31+
// conflicts with properties on other components or mixins.
32+
_backboneMixinIsMounted: false,
3033

3134
componentDidMount: function() {
32-
this._isMounted = true;
35+
this._backboneMixinIsMounted = true;
3336

3437
this._backboneModels = this.getBackboneModels();
3538
this._validateModelArray(this._backboneModels);
@@ -38,7 +41,7 @@ const BackboneMixin = {
3841
},
3942

4043
componentWillUnmount: function() {
41-
this._isMounted = false;
44+
this._backboneMixinIsMounted = false;
4245

4346
this._unbind(this._backboneModels);
4447
},
@@ -85,7 +88,7 @@ const BackboneMixin = {
8588
// TODO(joel): more rigorous fix needed? -- for the following error:
8689
// "Invariant Violation: forceUpdate(...): Can only force an update on
8790
// mounted or mounting components."
88-
if (this._isMounted) {
91+
if (this._backboneMixinIsMounted) {
8992
this.forceUpdate();
9093
}
9194
},

0 commit comments

Comments
 (0)