Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Upgrade to react 0.13 and dependencies #692

Merged
merged 6 commits into from
Apr 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions components/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ var TeachAPIClientMixin = require('../mixins/teach-api-client');
var ga = require('react-ga');

var LogoutLink = React.createClass({
mixins: [TeachAPIClientMixin, Router.State, React.addons.PureRenderMixin],
mixins: [TeachAPIClientMixin, React.addons.PureRenderMixin],
contextTypes: {
router: React.PropTypes.func
},
propTypes: {
origin: React.PropTypes.string
},
Expand All @@ -18,7 +21,8 @@ var LogoutLink = React.createClass({
};
},
render: function() {
var callbackURL = this.props.origin + this.getPathname();
var callbackURL = this.props.origin +
this.context.router.getCurrentPathname();
var loginBaseURL = this.getTeachAPI().baseURL;
var href = loginBaseURL + '/auth/oauth2/logout?callback=' +
encodeURIComponent(callbackURL);
Expand All @@ -31,7 +35,10 @@ var LogoutLink = React.createClass({
});

var LoginLink = React.createClass({
mixins: [TeachAPIClientMixin, Router.State, React.addons.PureRenderMixin],
mixins: [TeachAPIClientMixin, React.addons.PureRenderMixin],
contextTypes: {
router: React.PropTypes.func
},
propTypes: {
origin: React.PropTypes.string,
callbackSearch: React.PropTypes.string,
Expand All @@ -45,7 +52,8 @@ var LoginLink = React.createClass({
};
},
render: function() {
var callbackPath = this.getPathname() + this.props.callbackSearch;
var callbackPath = this.context.router.getCurrentPathname() +
this.props.callbackSearch;
var callbackURL = this.props.origin + callbackPath;
var loginBaseURL = this.getTeachAPI().baseURL;
var action = this.props.action;
Expand Down
7 changes: 5 additions & 2 deletions components/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ var DevRibbon = (process.env.NODE_ENV === 'production' &&
: require('./dev-ribbon.jsx');

var Page = React.createClass({
mixins: [Router.State],
contextTypes: {
router: React.PropTypes.func
},
childContextTypes: {
showModal: React.PropTypes.func.isRequired,
hideModal: React.PropTypes.func.isRequired,
Expand Down Expand Up @@ -61,7 +63,8 @@ var Page = React.createClass({
}
},
render: function() {
var pageClassName = this.getRoutes()[1].handler.pageClassName || '';
var routes = this.context.router.getCurrentRoutes();
var pageClassName = routes[1].handler.pageClassName || '';
return (
<div>
<div className={"page container-fluid " + pageClassName}
Expand Down
5 changes: 0 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var s3 = require('gulp-s3');
var gzip = require('gulp-gzip');
var less = require('gulp-less');
var cssmin = require('gulp-minify-css');
var prettify = require('gulp-html-prettify');
var webpack = require('gulp-webpack');
var plumber = require('gulp-plumber');
var merge = require('merge-stream');
Expand Down Expand Up @@ -179,10 +178,6 @@ gulp.task('generate-index-files', function() {
return new IndexFileStream(require('./lib/index-static.jsx'), {
meta: meta
})
.pipe(prettify({
indent_char: ' ',
indent_size: 2
}))
.pipe(gulp.dest('./dist'));
});

Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
"mofo-style": "^1.0.1",
"node-jsx": "^0.12.4",
"phantomjs": "^1.9.16",
"react": "^0.12.2",
"react-a11y": "0.0.6",
"react-ga": "^1.0.8",
"react-router": "^0.12.4",
"react": "^0.13.1",
"react-ga": "^1.0.12",
"react-router": "^0.13.2",
"react-select": "0.4.6",
"should": "^5.1.0",
"superagent": "^1.1.0",
Expand Down
12 changes: 9 additions & 3 deletions pages/clubs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ var validateClub = function(clubState) {

var ModalAddOrChangeYourClub = React.createClass({
mixins: [React.addons.LinkedStateMixin, ModalManagerMixin,
Router.Navigation, TeachAPIClientMixin],
TeachAPIClientMixin],
contextTypes: {
router: React.PropTypes.func
},
propTypes: {
// If club is provided, then we're a 'change' dialog, otherwise
// we're an 'add' dialog.
Expand Down Expand Up @@ -486,7 +489,10 @@ var ModalAddOrChangeYourClub = React.createClass({
});

var ClubsPage = React.createClass({
mixins: [ModalManagerMixin, TeachAPIClientMixin, Router.State],
mixins: [ModalManagerMixin, TeachAPIClientMixin],
contextTypes: {
router: React.PropTypes.func
},
statics: {
normalizeClub: normalizeClub,
validateClub: validateClub,
Expand All @@ -502,7 +508,7 @@ var ClubsPage = React.createClass({
componentDidMount: function() {
this.getTeachAPI().updateClubs();

if (this.getQuery().modal === 'add') {
if (this.context.router.getCurrentQuery().modal === 'add') {
this.showAddYourClubModal();
}
},
Expand Down
5 changes: 4 additions & 1 deletion test/browser/clubs-page.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var React =require('react/addons');
var TestUtils = React.addons.TestUtils;

var StubTeachAPI = require('./stub-teach-api');
var StubRouter = require('./stub-router');
var stubContext = require('./stub-context.jsx');
var ClubsPage = require('../../pages/clubs.jsx');

Expand Down Expand Up @@ -78,7 +79,9 @@ describe("ClubsPage", function() {

it('shows add modal if ?modal=add is in query', function() {
var clubsPage2 = stubContext.render(ClubsPage, {}, {
getCurrentQuery: function() { return {'modal': 'add'}; }
router: new StubRouter({
currentQuery: {'modal': 'add'}
})
});
clubsPage2.context.showModal.callCount.should.equal(1);
stubContext.unmount(clubsPage2);
Expand Down
7 changes: 4 additions & 3 deletions test/browser/login.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var Login = require('../../components/login.jsx');
var LoginLink = Login.LoginLink;
var LogoutLink = Login.LogoutLink;
var StubTeachAPI = require('./stub-teach-api');
var StubRouter = require('./stub-router');

describe("Login", function() {
var login, teachAPI;
Expand Down Expand Up @@ -84,9 +85,9 @@ function renderLink(linkClass, props) {
teachAPI.baseURL = 'http://teach-api';
return stubContext.render(linkClass, props, {
teachAPI: teachAPI,
getCurrentPathname: function() {
return '/path';
}
router: new StubRouter({
currentPathname: '/path'
})
});
}

Expand Down
8 changes: 5 additions & 3 deletions test/browser/modal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ var TestUtils = React.addons.TestUtils;

var Modal = require('../../components/modal.jsx');

var neverCalled = function() {
throw new Error("this should never be called");
};

var FakePage = React.createClass({
childContextTypes: {
hideModal: React.PropTypes.func.isRequired,
Expand All @@ -13,9 +17,7 @@ var FakePage = React.createClass({
getChildContext: function() {
return {
hideModal: this.props.onHideModal,
showModal: function() {
throw new Error("this should never be called");
}
showModal: neverCalled
};
},
render: function() {
Expand Down
40 changes: 12 additions & 28 deletions test/browser/stub-context.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,31 @@ var React =require('react/addons');
var TestUtils = React.addons.TestUtils;
var sinon = window.sinon;

var StubRouter = require('./stub-router');
var StubTeachAPI = require('./stub-teach-api');

var stubContext = function(Component, props, stubs) {
var childContext;
var func = React.PropTypes.func;
var noop = function() {};

return React.createClass({
childContextTypes: {
makePath: func,
makeHref: func,
transitionTo: func,
replaceWith: func,
goBack: func,
getCurrentPath: func,
getCurrentRoutes: func,
getCurrentPathname: func,
getCurrentParams: func,
getCurrentQuery: func,
isActive: func,
router: func,
showModal: func,
hideModal: func,
teachAPI: React.PropTypes.object
},

getChildContext: function() {
return _.extend({
makePath: noop,
makeHref: noop,
transitionTo: noop,
replaceWith: noop,
goBack: noop,
getCurrentPath: noop,
getCurrentRoutes: noop,
getCurrentPathname: noop,
getCurrentParams: noop,
getCurrentQuery: function() { return {}; },
isActive: noop,
showModal: sinon.spy(),
hideModal: sinon.spy(),
teachAPI: new StubTeachAPI()
}, stubs);
if (!childContext) {
childContext = _.extend({
router: new StubRouter(),
showModal: sinon.spy(),
hideModal: sinon.spy(),
teachAPI: new StubTeachAPI()
}, stubs);
}
return childContext;
},

render: function() {
Expand Down
27 changes: 27 additions & 0 deletions test/browser/stub-router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var _ = require('underscore');

var noop = function() {};

module.exports = function StubRouter(options) {
options = options || {};

var router = function() {
throw new Error("this should probably never be called");
};

router = _.extend(router, {
makePath: noop,
makeHref: noop,
transitionTo: noop,
replaceWith: noop,
goBack: noop,
getCurrentPath: noop,
getCurrentRoutes: noop,
getCurrentPathname: function() { return options.currentPathname || {}; },
getCurrentParams: noop,
getCurrentQuery: function() { return options.currentQuery || {}; },
isActive: noop
});

return router;
};