Skip to content

Commit

Permalink
fluxible-router: update to use latest fluxible-addons-react
Browse files Browse the repository at this point in the history
  • Loading branch information
pablopalacios committed Nov 11, 2020
1 parent 39af154 commit 2621d7d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 50 deletions.
13 changes: 4 additions & 9 deletions packages/fluxible-router/src/lib/createNavLinkComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'use strict';
var React = require('react');
var PropTypes = require('prop-types');
var { FluxibleContext } = require('fluxible-addons-react');
var RouteStore = require('./RouteStore');
var debug = require('debug')('NavLink');
var navigateAction = require('./navigateAction');
Expand Down Expand Up @@ -255,8 +256,7 @@ class NavLink extends React.Component {
try {
onBeforeUnloadText = window.onbeforeunload();
} catch(error) {
var logWarn = (this.context.logger && this.context.logger.warn) || console.warn;
logWarn('Warning: Call of window.onbeforeunload failed', error);
console.warn('Warning: Call of window.onbeforeunload failed', error);
}
}
var confirmResult = onBeforeUnloadText ? window.confirm(onBeforeUnloadText) : true;
Expand Down Expand Up @@ -291,8 +291,7 @@ class NavLink extends React.Component {
throw new Error('NavLink created with empty or missing href \'' + props.href +
'\'or unresolvable routeName \'' + props.routeName);
} else {
var logError = (this.context.logger && this.context.logger.error) || console.error;
logError('Error: Render NavLink with empty or missing href', props);
console.error('Error: Render NavLink with empty or missing href', props);
}
}

Expand Down Expand Up @@ -361,11 +360,7 @@ class NavLink extends React.Component {
NavLink._isMounted = false;
NavLink.autobind = false;
NavLink.displayName = 'NavLink';
NavLink.contextTypes = {
executeAction: PropTypes.func.isRequired,
getStore: PropTypes.func.isRequired,
logger: PropTypes.object
}
NavLink.contextType = FluxibleContext;
NavLink.propTypes = {
href: PropTypes.string,
stopPropagation: PropTypes.bool,
Expand Down
9 changes: 3 additions & 6 deletions packages/fluxible-router/src/lib/handleHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
var React = require('react');
var PropTypes = require('prop-types');
var debug = require('debug')('FluxibleRouter:handleHistory');
var { FluxibleContext } = require('fluxible-addons-react');
var handleRoute = require('../lib/handleRoute');
var navigateAction = require('../lib/navigateAction');
var History = require('./History');
Expand Down Expand Up @@ -59,10 +60,7 @@ function createComponent(Component, opts) {
inherits(HistoryHandler, React.Component);

HistoryHandler.displayName = 'HistoryHandler';
HistoryHandler.contextTypes = {
executeAction: PropTypes.func.isRequired,
logger: PropTypes.object
};
HistoryHandler.contextType = FluxibleContext;
HistoryHandler.propTypes = {
currentRoute: PropTypes.object,
currentNavigate: PropTypes.object
Expand Down Expand Up @@ -168,8 +166,7 @@ function createComponent(Component, opts) {
try {
onBeforeUnloadText = window.onbeforeunload();
} catch(error) {
var logWarn = (this.context.logger && this.context.logger.warn) || console.warn;
logWarn('Warning: Call of window.onbeforeunload failed', error);
console.warn('Warning: Call of window.onbeforeunload failed', error);
}
}
var confirmResult = onBeforeUnloadText ? window.confirm(onBeforeUnloadText) : true;
Expand Down
6 changes: 2 additions & 4 deletions packages/fluxible-router/src/lib/handleRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'use strict';
var React = require('react');
var PropTypes = require('prop-types');
var connectToStores = require('fluxible-addons-react').connectToStores;
var { connectToStores, FluxibleContext } = require('fluxible-addons-react');
var hoistNonReactStatics = require('hoist-non-react-statics');
var inherits = require('inherits');

Expand All @@ -19,9 +19,7 @@ function createComponent(Component) {
inherits(RouteHandler, React.Component);

RouteHandler.displayName = 'RouteHandler';
RouteHandler.contextTypes = {
getStore: PropTypes.func.isRequired
};
RouteHandler.contextType = FluxibleContext;
RouteHandler.propTypes = {
currentRoute: PropTypes.object,
currentNavigate: PropTypes.object,
Expand Down
27 changes: 12 additions & 15 deletions packages/fluxible-router/tests/mocks/MockAppComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,33 @@
'use strict';
var React = require('react');
var PropTypes = require('prop-types');
var provideContext = require('fluxible-addons-react').provideContext;
var { provideContext, FluxibleContext } = require('fluxible-addons-react');
var handleHistory = require('../../dist/lib/handleHistory');
var createReactClass = require('create-react-class');

var MockAppComponent = createReactClass({
contextTypes: {
getStore: PropTypes.func.isRequired
},
propTypes: {
children: PropTypes.object,
currentRoute: PropTypes.object
},
render: function () {
class MockAppComponent extends React.Component {
render() {
if (!this.props.children) {
return null;
}
return React.cloneElement(this.props.children, {
currentRoute: this.props.currentRoute
});
}
});
}

var customContextTypes = {
logger: PropTypes.object
MockAppComponent.contextType = FluxibleContext;

MockAppComponent.propTypes = {
children: PropTypes.object,
currentRoute: PropTypes.object
};

module.exports = provideContext(handleHistory(MockAppComponent, {
checkRouteOnPageLoad: false,
enableScroll: true
}), customContextTypes);
}));

module.exports.createWrappedMockAppComponent = function createWrappedMockAppComponent(opts) {
return provideContext(handleHistory(MockAppComponent, opts), customContextTypes);
return provideContext(handleHistory(MockAppComponent, opts));
};
17 changes: 6 additions & 11 deletions packages/fluxible-router/tests/unit/lib/NavLink-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,8 @@ describe('NavLink', function () {

it('should ignore any error which happens when calling onbeforeunload', function (done) {
var loggerWarning;
mockContext.logger = {
warn: function () {
loggerWarning = arguments;
}
global.console.warn = (...args) => {
loggerWarning = args;
};
global.window.onbeforeunload = function () {
throw new Error('Test error');
Expand Down Expand Up @@ -679,17 +677,14 @@ describe('NavLink NODE_ENV === development', function () {
describe('NavLink NODE_ENV === production', function () {
var mockContext;
var loggerError;
var logger = {
error: function () {
loggerError = arguments;
}
};

beforeEach(function (done) {
loggerError = null;
global.console.error = (...args) => {
loggerError = args;
};

setup({nodeEnv: 'production'}, function (err, context) {
mockContext = context;
mockContext.logger = logger;
done(err);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,7 @@ describe('handleHistory', function () {

it('should ignore any error which happens when calling onbeforeunload', function (done) {
var loggerWarning;
mockContext.logger = {
warn: function () {
loggerWarning = arguments;
}
};
global.console.warn = (...args) => { loggerWarning = args; };
global.window.confirm = function () { return false; };
global.window.onbeforeunload = function () {
throw new Error('Test error');
Expand Down

0 comments on commit 2621d7d

Please sign in to comment.