Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Bug] cleanup injector error msg (#915)

Shan He407bce8488a2
diff --git a/src/components/container.js b/src/components/container.js
index d73a52d10..966654fc1 100644
--- a/src/components/container.js
+++ b/src/components/container.js
@@ -33,19 +33,11 @@ import {
} from 'actions/identity-actions';
import {notNullorUndefined} from 'utils/data-utils';
-export const errorMsg = {
+export const ERROR_MSG = {
noState:
- `kepler.gl state doesnt exist. ` +
+ `kepler.gl state does not exist. ` +
`You might forget to mount keplerGlReducer in your root reducer.` +
- `If it is not mounted as state.keplerGl by default, you need to provide getState as a prop`,
-
- wrongType: type =>
- `injectComponents takes an array of factories replacement pairs as input, ` +
- `${type} is provided`,
-
- wrongPairType:
- `injectComponents takes an array of factories replacement pairs as input, ` +
- `each pair be a array as [originalFactory, replacement]`
+ `If it is not mounted as state.keplerGl by default, you need to provide getState as a prop`
};
ContainerFactory.deps = [KeplerGlFactory];
@@ -91,7 +83,7 @@ export function ContainerFactory(KeplerGl) {
this.getSelector = memoize((id, getState) => state => {
if (!getState(state)) {
// log error
- Console.error(errorMsg.noState);
+ Console.error(ERROR_MSG.noState);
return null;
}
diff --git a/src/components/injector.js b/src/components/injector.js
index 44e1ff3b5..e0bd5fcba 100644
--- a/src/components/injector.js
+++ b/src/components/injector.js
@@ -26,11 +26,16 @@ import KeplerGlContext from 'components/context';
const MissingComp = () => <div />;
-export const errorMsg = {
+export const ERROR_MSG = {
+ wrongRecipeType:
+ `injectComponents takes an array of factories replacement pairs as input, ` +
+ `each pair be a array as [originalFactory, replacement].`,
+
noDep: (fac, parent) =>
`${fac.name} is required as a dependency of ${parent.name}, ` +
`but is not provided to injectComponents. It will not be rendered.`,
- notFunc: '`factory and its replacement should be a function`'
+
+ notFunc: 'factory and its replacement should be a function'
};
export function injector(map = new Map()) {
@@ -39,7 +44,7 @@ export function injector(map = new Map()) {
const factory = map.get(fac);
// factory is not injected
if (!factory) {
- Console.error(errorMsg.noDep(fac, parent));
+ Console.error(ERROR_MSG.noDep(fac, parent));
return MissingComp;
}
@@ -69,18 +74,19 @@ export function injector(map = new Map()) {
export function typeCheckRecipe(recipe) {
if (!Array.isArray(recipe) || recipe.length < 2) {
- Console.error(errorMsg.wrongPairType);
+ Console.error('Error injecting [factory, replacement]', recipe);
+ Console.error(ERROR_MSG.wrongRecipeType);
return false;
}
const [factory, replacement] = recipe;
if (typeof factory !== 'function') {
Console.error('Error injecting factory: ', factory);
- Console.error(errorMsg.notFunc);
+ Console.error(ERROR_MSG.notFunc);
return false;
} else if (typeof replacement !== 'function') {
Console.error('Error injecting replacement for: ', factory);
- Console.error(errorMsg.notFunc);
+ Console.error(ERROR_MSG.notFunc);
return false;
}
diff --git a/test/browser/components/container-test.js b/test/browser/components/container-test.js
index cdc4f515d..d1324d800 100644
--- a/test/browser/components/container-test.js
+++ b/test/browser/components/container-test.js
@@ -31,7 +31,7 @@ import rootReducer from 'reducers/root';
import coreReducer from 'reducers/core';
import {keplerGlInit} from 'actions/actions';
-import Container, {errorMsg} from 'components/container';
+import Container, {ERROR_MSG} from 'components/container';
import {DEFAULT_MAPBOX_API_URL} from 'constants/default-settings';
const initialCoreState = coreReducer(undefined, keplerGlInit());
const initialState = {
@@ -54,7 +54,7 @@ test('Components -> Container -> Mount with mint:true', t => {
t.ok(spy.calledOnce, 'should call console.error once');
t.equal(
spy.getCall(0).args[0],
- errorMsg.noState,
+ ERROR_MSG.noState,
'should warn when cannot find kepler.gl state'
);
diff --git a/test/browser/components/injector-test.js b/test/browser/components/injector-test.js
index 356f0c686..a401153d3 100644
--- a/test/browser/components/injector-test.js
+++ b/test/browser/components/injector-test.js
@@ -29,13 +29,12 @@ import {console as Console} from 'global/window';
import {
withState,
injectComponents,
- PanelHeaderFactory,
- MapContainerFactory
+ PanelHeaderFactory
} from 'components';
import coreReducer from 'reducers/core';
import {keplerGlInit} from 'actions/actions';
-import {errorMsg} from 'components/injector';
+import {ERROR_MSG} from 'components/injector';
import {visStateLens, uiStateLens, mapStateLens, mapStyleLens} from 'reducers';
const mockStore = configureStore();