Skip to content

Commit eafa1f7

Browse files
committed
Merge branch 'remove-route-store'
Conflicts: modules/components/Routes.js
2 parents eeb5bac + 77ba566 commit eafa1f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2208
-1893
lines changed

examples/data-flow/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ var Routes = Router.Routes;
66
var Link = Router.Link;
77

88
var App = React.createClass({
9+
10+
mixins: [ Router.Transitions ],
11+
912
getInitialState: function() {
1013
return {
1114
tacos: [
@@ -28,7 +31,7 @@ var App = React.createClass({
2831
return taco.name != removedTaco;
2932
});
3033
this.setState({tacos: tacos});
31-
Router.transitionTo('/');
34+
this.transitionTo('/');
3235
},
3336

3437
render: function() {

examples/master-detail/app.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ var Index = React.createClass({
132132
});
133133

134134
var Contact = React.createClass({
135+
136+
mixins: [ Router.Transitions ],
137+
135138
getStateFromStore: function(props) {
136139
props = props || this.props;
137140
return {
@@ -164,7 +167,7 @@ var Contact = React.createClass({
164167

165168
destroy: function() {
166169
ContactStore.removeContact(this.props.params.id);
167-
Router.transitionTo('/');
170+
this.transitionTo('/');
168171
},
169172

170173
render: function() {
@@ -182,14 +185,17 @@ var Contact = React.createClass({
182185
});
183186

184187
var NewContact = React.createClass({
188+
189+
mixins: [ Router.Transitions ],
190+
185191
createContact: function(event) {
186192
event.preventDefault();
187193
ContactStore.addContact({
188194
first: this.refs.first.getDOMNode().value,
189195
last: this.refs.last.getDOMNode().value
190196
}, function(contact) {
191-
Router.transitionTo('contact', { id: contact.id });
192-
});
197+
this.transitionTo('contact', { id: contact.id });
198+
}.bind(this));
193199
},
194200

195201
render: function() {

examples/transitions/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ var Dashboard = React.createClass({
2626
});
2727

2828
var Form = React.createClass({
29+
30+
mixins: [ Router.Transitions ],
31+
2932
statics: {
3033
willTransitionFrom: function(transition, component) {
3134
if (component.refs.userInput.getDOMNode().value !== '') {
@@ -39,7 +42,7 @@ var Form = React.createClass({
3942
handleSubmit: function(event) {
4043
event.preventDefault();
4144
this.refs.userInput.getDOMNode().value = '';
42-
Router.transitionTo('/');
45+
this.transitionTo('/');
4346
},
4447

4548
render: function() {

karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ module.exports = function(config) {
66
frameworks: ['mocha', 'browserify'],
77

88
files: [
9-
'specs/main.js'
9+
'tests.js'
1010
],
1111

1212
exclude: [],
1313

1414
preprocessors: {
15-
'specs/main.js': ['browserify']
15+
'tests.js': ['browserify']
1616
},
1717

1818
browserify: {

modules/.DS_Store

-6 KB
Binary file not shown.

modules/actions/LocationActions.js

Lines changed: 10 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,27 @@
1-
var supportsHistory = require('../utils/supportsHistory');
2-
var HistoryLocation = require('../locations/HistoryLocation');
3-
var RefreshLocation = require('../locations/RefreshLocation');
4-
var LocationDispatcher = require('../dispatchers/LocationDispatcher');
5-
var ActionTypes = require('../constants/ActionTypes');
6-
var warning = require('react/lib/warning');
7-
var isAbsoluteURL = require('../utils/isAbsoluteURL');
8-
var makePath = require('../utils/makePath');
9-
10-
function loadURL(url) {
11-
window.location = url;
12-
}
13-
14-
var _location = null;
15-
var _isDispatching = false;
16-
var _previousPath = null;
17-
18-
function dispatchAction(actionType, operation) {
19-
if (_isDispatching)
20-
throw new Error('Cannot handle ' + actionType + ' in the middle of another action.');
21-
22-
_isDispatching = true;
23-
24-
var scrollPosition = {
25-
x: window.scrollX,
26-
y: window.scrollY
27-
};
28-
29-
if (typeof operation === 'function')
30-
operation(_location);
31-
32-
var path = _location.getCurrentPath();
33-
LocationDispatcher.handleViewAction({
34-
type: actionType,
35-
path: path,
36-
scrollPosition: scrollPosition
37-
});
38-
39-
_isDispatching = false;
40-
_previousPath = path;
41-
}
42-
43-
function handleChange() {
44-
var path = _location.getCurrentPath();
45-
46-
// Ignore changes inside or caused by dispatchAction
47-
if (!_isDispatching && path !== _previousPath) {
48-
dispatchAction(ActionTypes.POP);
49-
}
50-
}
51-
521
/**
532
* Actions that modify the URL.
543
*/
554
var LocationActions = {
565

57-
getLocation: function () {
58-
return _location;
59-
},
60-
61-
setup: function (location) {
62-
// When using HistoryLocation, automatically fallback
63-
// to RefreshLocation in browsers that do not support
64-
// the HTML5 history API.
65-
if (location === HistoryLocation && !supportsHistory())
66-
location = RefreshLocation;
67-
68-
if (_location !== null) {
69-
warning(
70-
_location === location,
71-
'Cannot use location %s, already using %s', location, _location
72-
);
73-
return;
74-
}
75-
76-
_location = location;
77-
78-
if (_location !== null) {
79-
dispatchAction(ActionTypes.SETUP, function (location) {
80-
if (typeof location.setup === 'function')
81-
location.setup(handleChange);
82-
});
83-
}
84-
},
85-
86-
teardown: function () {
87-
if (_location !== null) {
88-
if (typeof _location.teardown === 'function')
89-
_location.teardown();
90-
91-
_location = null;
92-
}
93-
},
6+
/**
7+
* Indicates a location is being setup for the first time.
8+
*/
9+
SETUP: 'setup',
9410

9511
/**
96-
* Transitions to the URL specified in the arguments by pushing
97-
* a new URL onto the history stack.
12+
* Indicates a new location is being pushed to the history stack.
9813
*/
99-
transitionTo: function (to, params, query) {
100-
if (isAbsoluteURL(to)) {
101-
loadURL(to);
102-
} else {
103-
dispatchAction(ActionTypes.PUSH, function (location) {
104-
var path = makePath(to, params, query);
105-
location.push(path);
106-
});
107-
}
108-
},
14+
PUSH: 'push',
10915

11016
/**
111-
* Transitions to the URL specified in the arguments by replacing
112-
* the current URL in the history stack.
17+
* Indicates the current location should be replaced.
11318
*/
114-
replaceWith: function (to, params, query) {
115-
if (isAbsoluteURL(to)) {
116-
loadURL(to);
117-
} else {
118-
dispatchAction(ActionTypes.REPLACE, function (location) {
119-
var path = makePath(to, params, query);
120-
location.replace(path);
121-
});
122-
}
123-
},
19+
REPLACE: 'replace',
12420

12521
/**
126-
* Transitions to the previous URL.
22+
* Indicates the most recent entry should be removed from the history stack.
12723
*/
128-
goBack: function () {
129-
dispatchAction(ActionTypes.POP, function (location) {
130-
location.pop();
131-
});
132-
}
24+
POP: 'pop'
13325

13426
};
13527

0 commit comments

Comments
 (0)