Skip to content

Commit 50372fe

Browse files
committed
Revert "listen to history for active state changes, store active state in component state"
This reverts commit 57206a6. Conflicts: modules/Link.js modules/__tests__/Link-test.js
1 parent b833d55 commit 50372fe

File tree

1 file changed

+1
-42
lines changed

1 file changed

+1
-42
lines changed

modules/Link.js

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,46 +54,6 @@ var Link = React.createClass({
5454
};
5555
},
5656

57-
getInitialState() {
58-
var active = this.getActiveState();
59-
return { active };
60-
},
61-
62-
trySubscribe() {
63-
var { history } = this.context;
64-
if (!history) return;
65-
this._unlisten = history.listen(this.handleHistoryChange);
66-
},
67-
68-
tryUnsubscribe() {
69-
if (!this._unlisten) return;
70-
this._unlisten();
71-
this._unlisten = undefined;
72-
},
73-
74-
handleHistoryChange() {
75-
var { active } = this.state;
76-
var nextActive = this.getActiveState();
77-
if (active !== nextActive) {
78-
this.setState({ active: nextActive });
79-
}
80-
},
81-
82-
getActiveState() {
83-
var { history } = this.context;
84-
var { to, query, onlyActiveOnIndex } = this.props;
85-
if (!history) return false;
86-
return history.isActive(to, query, onlyActiveOnIndex);
87-
},
88-
89-
componentDidMount() {
90-
this.trySubscribe();
91-
},
92-
93-
componentWillUnmount() {
94-
this.tryUnsubscribe();
95-
},
96-
9757
handleClick(event) {
9858
var allowTransition = true;
9959
var clickResult;
@@ -131,14 +91,13 @@ var Link = React.createClass({
13191
};
13292

13393
var { history } = this.context;
134-
var { active } = this.state;
13594

13695
// Ignore if rendered outside the context
13796
// of history, simplifies unit testing.
13897
if (history) {
13998
props.href = history.createHref(to, query);
14099

141-
if (active) {
100+
if (history.isActive(to, query, onlyActiveOnIndex)) {
142101
if (props.activeClassName)
143102
props.className += props.className !== '' ? ` ${props.activeClassName}` : props.activeClassName;
144103

0 commit comments

Comments
 (0)