diff --git a/packages/fluxible-router/src/lib/createNavLinkComponent.js b/packages/fluxible-router/src/lib/createNavLinkComponent.js index 1d554936..c6051a5c 100644 --- a/packages/fluxible-router/src/lib/createNavLinkComponent.js +++ b/packages/fluxible-router/src/lib/createNavLinkComponent.js @@ -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'); @@ -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; @@ -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); } } @@ -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, diff --git a/packages/fluxible-router/src/lib/handleHistory.js b/packages/fluxible-router/src/lib/handleHistory.js index 2c9c632e..d79b5ddc 100644 --- a/packages/fluxible-router/src/lib/handleHistory.js +++ b/packages/fluxible-router/src/lib/handleHistory.js @@ -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'); @@ -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 @@ -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; diff --git a/packages/fluxible-router/src/lib/handleRoute.js b/packages/fluxible-router/src/lib/handleRoute.js index fb3ecd17..dca4800f 100644 --- a/packages/fluxible-router/src/lib/handleRoute.js +++ b/packages/fluxible-router/src/lib/handleRoute.js @@ -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'); @@ -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, diff --git a/packages/fluxible-router/tests/mocks/MockAppComponent.js b/packages/fluxible-router/tests/mocks/MockAppComponent.js index 828a405d..e0db527d 100644 --- a/packages/fluxible-router/tests/mocks/MockAppComponent.js +++ b/packages/fluxible-router/tests/mocks/MockAppComponent.js @@ -5,19 +5,12 @@ '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; } @@ -25,27 +18,28 @@ var MockAppComponent = createReactClass({ 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)); }; module.exports.createDecoratedMockAppComponent = function createDecoratedMockAppComponent(opts) { - @provideContext - @handleHistory(opts) class DecoratedMockAppComponent extends React.Component { - static contextTypes = { - getStore: PropTypes.func.isRequired - }; + static contextType = FluxibleContext; static propTypes = { children: PropTypes.object, currentRoute: PropTypes.object @@ -63,5 +57,5 @@ module.exports.createDecoratedMockAppComponent = function createDecoratedMockApp } } - return DecoratedMockAppComponent; + return provideContext(handleHistory(DecoratedMockAppComponent, opts)); }; diff --git a/packages/fluxible-router/tests/unit/lib/NavLink-test.js b/packages/fluxible-router/tests/unit/lib/NavLink-test.js index 2157e75b..c4d4c0b1 100644 --- a/packages/fluxible-router/tests/unit/lib/NavLink-test.js +++ b/packages/fluxible-router/tests/unit/lib/NavLink-test.js @@ -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'); @@ -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); }); }); diff --git a/packages/fluxible-router/tests/unit/lib/handleHistory-test.js b/packages/fluxible-router/tests/unit/lib/handleHistory-test.js index e997e7d5..5ec1eebc 100644 --- a/packages/fluxible-router/tests/unit/lib/handleHistory-test.js +++ b/packages/fluxible-router/tests/unit/lib/handleHistory-test.js @@ -415,10 +415,8 @@ 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 () {