Skip to content

Commit 3e276b4

Browse files
committed
[internal] withMessages HOC simplification - remove indirection
1 parent 3b920c7 commit 3e276b4

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/lib/withMessages.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,23 @@ function enhanceWithMessages(keyPrefix: string | undefined, WrappedComponent: Re
3838
}
3939

4040
/**
41-
* An internal implementation of the argument resolution logic.
41+
* Creates a higher order component and provides the MessageSourceApi as `props`.
4242
*
43-
* @param keyPrefixOrComponent the passed argument ([Component] | [[keyPrefix], [Component]])
44-
*/
45-
function internalWithMessages(keyPrefixOrComponent?: string | React.ComponentType<any>) {
46-
if (keyPrefixOrComponent == null || typeof keyPrefixOrComponent === 'string') {
47-
// consumer used the curried API
48-
return enhanceWithMessages.bind(undefined, keyPrefixOrComponent);
49-
}
50-
51-
return enhanceWithMessages(undefined, keyPrefixOrComponent);
52-
}
53-
54-
/**
5543
* Example usages:
5644
*
5745
* 1. MessageSource.withMessages('keyPrefix')(Component)
5846
* 2. MessageSource.withMessages(Component)
5947
* 3. compose(MessageSource.withMessages('keyPrefix'))(Component)
6048
* 4. compose(MessageSource.withMessages)(Component)
49+
*
50+
* @param keyPrefixOrComponent the passed argument ([Component] | [[keyPrefix], [Component]])
6151
*/
62-
export const withMessages = internalWithMessages;
52+
export function withMessages(keyPrefixOrComponent?: string | React.ComponentType<any>) {
53+
if (keyPrefixOrComponent == null || typeof keyPrefixOrComponent === 'string') {
54+
return function wrapWithMessages(Component: React.ComponentType<any>) {
55+
return enhanceWithMessages(keyPrefixOrComponent, Component);
56+
};
57+
}
58+
59+
return enhanceWithMessages(undefined, keyPrefixOrComponent);
60+
}

0 commit comments

Comments
 (0)