Skip to content

Commit

Permalink
Merge pull request #79 from grahammendick/skiprerender
Browse files Browse the repository at this point in the history
  • Loading branch information
grahammendick authored Aug 30, 2016
2 parents 745b1dd + 7b7af66 commit bd66b50
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
25 changes: 22 additions & 3 deletions NavigationReact/src/NavigationBackLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ import Navigation = require('navigation');
import React = require('react');

class NavigationBackLink extends React.Component<any, any> {
private onNavigate = () => this.forceUpdate();

private onNavigate = () => {
if (this.state.stateContext !== this.getStateNavigator().stateContext.url
|| this.state.crumb !== this.getNavigationBackLink())
this.setState(this.getNextState());
}

constructor(props, context) {
super(props, context);
this.state = this.getNextState();
}

static contextTypes = {
stateNavigator: React.PropTypes.object
}
Expand All @@ -16,12 +25,22 @@ class NavigationBackLink extends React.Component<any, any> {
private getNavigationBackLink(): string {
return LinkUtility.getLink(this.getStateNavigator(), () => this.getStateNavigator().getNavigationBackLink(this.props.distance));
}


private getNextState() {
return {
stateContext: this.getStateNavigator().stateContext.url,
crumb: this.getNavigationBackLink()
};
}

componentDidMount() {
if (!this.props.lazy)
this.getStateNavigator().onNavigate(this.onNavigate);
}

componentWillReceiveProps() {
this.setState(this.getNextState());
}
componentWillUnmount() {
if (!this.props.lazy)
this.getStateNavigator().offNavigate(this.onNavigate);
Expand Down
22 changes: 19 additions & 3 deletions NavigationReact/src/NavigationLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import Navigation = require('navigation');
import React = require('react');

class NavigationLink extends React.Component<any, any> {
private onNavigate = () => this.forceUpdate();

private onNavigate = () => {
if (this.state.stateContext !== this.getStateNavigator().stateContext.url)
this.setState(this.getNextState());
}

constructor(props, context) {
super(props, context);
this.state = this.getNextState();
}

static contextTypes = {
stateNavigator: React.PropTypes.object
}
Expand All @@ -18,11 +26,19 @@ class NavigationLink extends React.Component<any, any> {
return LinkUtility.getLink(this.getStateNavigator(), () => this.getStateNavigator().getNavigationLink(this.props.stateKey, navigationData));
}

private getNextState() {
return { stateContext: this.getStateNavigator().stateContext.url };
}

componentDidMount() {
if (!this.props.lazy)
this.getStateNavigator().onNavigate(this.onNavigate);
}


componentWillReceiveProps() {
this.setState(this.getNextState());
}

componentWillUnmount() {
if (!this.props.lazy)
this.getStateNavigator().offNavigate(this.onNavigate);
Expand Down
24 changes: 20 additions & 4 deletions NavigationReact/src/RefreshLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import Navigation = require('navigation');
import React = require('react');

class RefreshLink extends React.Component<any, any> {
private onNavigate = () => this.forceUpdate();

private onNavigate = () => {
if (this.state.stateContext !== this.getStateNavigator().stateContext.url)
this.setState(this.getNextState());
}

constructor(props, context) {
super(props, context);
this.state = this.getNextState();
}

static contextTypes = {
stateNavigator: React.PropTypes.object
}
Expand All @@ -13,16 +21,24 @@ class RefreshLink extends React.Component<any, any> {
return this.props.stateNavigator || (<any> this.context).stateNavigator;
}

getRefreshLink(): string {
private getRefreshLink(): string {
var navigationData = LinkUtility.getData(this.getStateNavigator(), this.props.navigationData, this.props.includeCurrentData, this.props.currentDataKeys);
return LinkUtility.getLink(this.getStateNavigator(), () => this.getStateNavigator().getRefreshLink(navigationData));
}

private getNextState() {
return { stateContext: this.getStateNavigator().stateContext.url };
}

componentDidMount() {
if (!this.props.lazy)
this.getStateNavigator().onNavigate(this.onNavigate);
}


componentWillReceiveProps() {
this.setState(this.getNextState());
}

componentWillUnmount() {
if (!this.props.lazy)
this.getStateNavigator().offNavigate(this.onNavigate);
Expand Down

0 comments on commit bd66b50

Please sign in to comment.