Skip to content

Commit

Permalink
[removed] RouteStore
Browse files Browse the repository at this point in the history
[added] Router.PathState for keeping track of the current URL path
[added] Router.RouteLookup for looking up routes
[added] Router.Transitions for transitioning to other routes
[added] Pluggable scroll behaviors
[changed] <Routes preserveScrollPosition> => <Routes scrollBehavior>
[removed] <Route preserveScrollPosition>
[removed] Router.transitionTo, Router.replaceWith, Router.goBack
  • Loading branch information
mjackson committed Sep 29, 2014
1 parent c96e34d commit f2bf4bd
Show file tree
Hide file tree
Showing 28 changed files with 1,222 additions and 938 deletions.
58 changes: 8 additions & 50 deletions modules/actions/LocationActions.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,27 @@
var LocationDispatcher = require('../dispatchers/LocationDispatcher');
var isAbsoluteURL = require('../utils/isAbsoluteURL');
var makePath = require('../utils/makePath');

function loadURL(url) {
window.location = url;
}

/**
* Actions that modify the URL.
*/
var LocationActions = {

PUSH: 'push',
REPLACE: 'replace',
POP: 'pop',
UPDATE_SCROLL: 'update-scroll',

/**
* Transitions to the URL specified in the arguments by pushing
* a new URL onto the history stack.
* Indicates a location is being setup for the first time.
*/
transitionTo: function (to, params, query) {
if (isAbsoluteURL(to)) {
loadURL(to);
} else {
LocationDispatcher.handleViewAction({
type: LocationActions.PUSH,
path: makePath(to, params, query)
});
}
},
SETUP: 'setup',

/**
* Transitions to the URL specified in the arguments by replacing
* the current URL in the history stack.
* Indicates a new location is being pushed to the history stack.
*/
replaceWith: function (to, params, query) {
if (isAbsoluteURL(to)) {
loadURL(to);
} else {
LocationDispatcher.handleViewAction({
type: LocationActions.REPLACE,
path: makePath(to, params, query)
});
}
},
PUSH: 'push',

/**
* Transitions to the previous URL.
* Indicates the current location should be replaced.
*/
goBack: function () {
LocationDispatcher.handleViewAction({
type: LocationActions.POP
});
},
REPLACE: 'replace',

/**
* Updates the window's scroll position to the last known position
* for the current URL path.
* Indicates the most recent entry should be removed from the history stack.
*/
updateScroll: function () {
LocationDispatcher.handleViewAction({
type: LocationActions.UPDATE_SCROLL
});
}
POP: 'pop'

};

Expand Down
12 changes: 6 additions & 6 deletions modules/components/Link.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var React = require('react');
var warning = require('react/lib/warning');
var ActiveState = require('../mixins/ActiveState');
var transitionTo = require('../actions/LocationActions').transitionTo;
var RouteLookup = require('../mixins/RouteLookup');
var Transitions = require('../mixins/Transitions');
var withoutProperties = require('../utils/withoutProperties');
var hasOwnProperty = require('../utils/hasOwnProperty');
var makeHref = require('../utils/makeHref');
var warning = require('react/lib/warning');

function isLeftClickEvent(event) {
return event.button === 0;
Expand Down Expand Up @@ -51,7 +51,7 @@ var Link = React.createClass({

displayName: 'Link',

mixins: [ ActiveState ],
mixins: [ ActiveState, RouteLookup, Transitions ],

statics: {

Expand Down Expand Up @@ -99,7 +99,7 @@ var Link = React.createClass({
* Returns the value of the "href" attribute to use on the DOM element.
*/
getHref: function () {
return makeHref(this.props.to, Link.getParams(this.props), this.props.query);
return this.makeHref(this.props.to, Link.getParams(this.props), this.props.query);
},

/**
Expand Down Expand Up @@ -145,7 +145,7 @@ var Link = React.createClass({
event.preventDefault();

if (allowTransition)
transitionTo(this.props.to, Link.getParams(this.props), this.props.query);
this.transitionTo(this.props.to, Link.getParams(this.props), this.props.query);
},

render: function () {
Expand Down

0 comments on commit f2bf4bd

Please sign in to comment.