Skip to content

Commit

Permalink
Revert "listen to history for active state changes, store active stat…
Browse files Browse the repository at this point in the history
…e in component state"

This reverts commit 57206a6.

Conflicts:
	modules/Link.js
	modules/__tests__/Link-test.js
  • Loading branch information
ryanflorence committed Sep 11, 2015
1 parent b833d55 commit 50372fe
Showing 1 changed file with 1 addition and 42 deletions.
43 changes: 1 addition & 42 deletions modules/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,46 +54,6 @@ var Link = React.createClass({
};
},

getInitialState() {
var active = this.getActiveState();
return { active };
},

trySubscribe() {
var { history } = this.context;
if (!history) return;
this._unlisten = history.listen(this.handleHistoryChange);
},

tryUnsubscribe() {
if (!this._unlisten) return;
this._unlisten();
this._unlisten = undefined;
},

handleHistoryChange() {
var { active } = this.state;
var nextActive = this.getActiveState();
if (active !== nextActive) {
this.setState({ active: nextActive });
}
},

getActiveState() {
var { history } = this.context;
var { to, query, onlyActiveOnIndex } = this.props;
if (!history) return false;
return history.isActive(to, query, onlyActiveOnIndex);
},

componentDidMount() {
this.trySubscribe();
},

componentWillUnmount() {
this.tryUnsubscribe();
},

handleClick(event) {
var allowTransition = true;
var clickResult;
Expand Down Expand Up @@ -131,14 +91,13 @@ var Link = React.createClass({
};

var { history } = this.context;
var { active } = this.state;

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

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

Expand Down

0 comments on commit 50372fe

Please sign in to comment.