Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const makeHook = storeInterface => {
invariant(isObject(storeInterface), 'The store interface is undefined.');
const { getEntries, ejectionKey, injectionKey, type } = storeInterface;
const pascalCaseType = toPascalCase(type);
const hookName = `use${pascalCaseType}`;
const useInjectables = (injectables, options = {}) => {
const injectableKeys = keys(injectables);
const locationMessage =
`@redux-tools: This warning happened while injecting the following ${type}: ` +
`${injectableKeys}.`;
const warn = (...args) => console.warn(locationMessage, ...args);
// NOTE: `options.global` and `options.persist` are deprecated.
const enhanceStore = (prevStore, storeInterface, { onEjected = noop, onInjected = noop } = {}) => {
invariant(
isObject(prevStore),
'You must pass a Redux store as the first argument to `enhanceStore()`'
);
invariant(
isObject(storeInterface),
'You must pass a store interface as the second argument to `enhanceStore()`'
);
const { injectionKey, ejectionKey, getEntries, setEntries, type } = storeInterface;
const { dispatch = noop } = prevStore;
const actionType = toScreamingSnakeCase(type);
const inject = (injectables, props = {}) => {
const entries = createEntries(injectables, props);
forEach(
entry =>
invariant(
// NOTE: `isFunction` from ramda-extension returns `false` for `jest.fn()`.
typeof entry.value === 'function',
`Injecting ${type}, but the value of ${JSON.stringify(entry)} is not a function.`
[(a, b) => isObject(a) && isObject(b), mergeDeepLeft],
[T, headArg],
ownProps
) => {
if (!mapDispatchToProps) {
return {};
}
const wrappedDispatch = o(
dispatch,
mergeDeepRight({ meta: { namespace: ownProps.namespace } })
);
if (isFunction(mapDispatchToProps)) {
return mapDispatchToProps(wrappedDispatch, ownProps);
}
if (isObject(mapDispatchToProps)) {
const wrapActionCreator = actionCreator =>
compose(
wrappedDispatch,
actionCreator
);
return map(wrapActionCreator, mapDispatchToProps);
}
throw new TypeError('mapDispatchToProps is not an object or a function');
};
const enhanceStore = (prevStore, storeInterface, { onEjected = noop, onInjected = noop } = {}) => {
invariant(
isObject(prevStore),
'You must pass a Redux store as the first argument to `enhanceStore()`'
);
invariant(
isObject(storeInterface),
'You must pass a store interface as the second argument to `enhanceStore()`'
);
const { injectionKey, ejectionKey, getEntries, setEntries, type } = storeInterface;
const { dispatch = noop } = prevStore;
const actionType = toScreamingSnakeCase(type);
const inject = (injectables, props = {}) => {
const entries = createEntries(injectables, props);
forEach(
const makeDecorator = config => {
invariant(isObject(config), 'The injector config is undefined.');
const useInjectables = makeHook(config);
const { type } = config;
const decoratorName = type ? `With${toPascalCase(type)}` : 'Injector';
return (injectables, options = {}) => NextComponent => {
const Injector = ({ feature: propFeature, namespace: propNamespace, ...otherProps }) => {
const feature = options.feature || propFeature || DEFAULT_FEATURE;
const contextNamespace = useNamespace(feature);
const namespace = options.namespace || propNamespace || contextNamespace;
const isInitialized = useInjectables(injectables, { ...options, feature, namespace });
if (isInitialized) {
return (