mirror of
https://github.com/wassname/talk.git
synced 2026-07-26 13:37:38 +08:00
WIP
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
import * as React from "react";
|
||||
import {
|
||||
hoistStatics,
|
||||
InferableComponentEnhancer,
|
||||
wrapDisplayName,
|
||||
} from "recompose";
|
||||
import React from "react";
|
||||
import { hoistStatics, wrapDisplayName } from "recompose";
|
||||
|
||||
import { Omit } from "talk-ui/types";
|
||||
import { TalkContext, TalkContextConsumer } from "./TalkContext";
|
||||
|
||||
// Injects props and removes them from the prop requirements.
|
||||
// Will not pass through the injected props if they are passed in during
|
||||
// render. Also adds new prop requirements from TNeedsProps.
|
||||
type InferableComponentEnhancerWithProps<TInjectedProps> = <
|
||||
P extends TInjectedProps
|
||||
>(
|
||||
component: React.ComponentType<P>
|
||||
) => React.ComponentType<Omit<P, keyof TInjectedProps>>;
|
||||
|
||||
/**
|
||||
* withContext is a HOC wrapper around `TalkContextConsumer`.
|
||||
* `propsCallback` must be provided which accepts the `TalkContext`
|
||||
@@ -14,7 +20,7 @@ import { TalkContext, TalkContextConsumer } from "./TalkContext";
|
||||
*/
|
||||
function withContext<T>(
|
||||
propsCallback: (context: TalkContext) => T
|
||||
): InferableComponentEnhancer<T> {
|
||||
): InferableComponentEnhancerWithProps<T> {
|
||||
return hoistStatics<T>(
|
||||
<U extends T>(WrappedComponent: React.ComponentType<U>) => {
|
||||
const Component: React.StatelessComponent<any> = props => (
|
||||
@@ -27,7 +33,7 @@ function withContext<T>(
|
||||
Component.displayName = wrapDisplayName(WrappedComponent, "withContext");
|
||||
return Component;
|
||||
}
|
||||
);
|
||||
) as any;
|
||||
}
|
||||
|
||||
export default withContext;
|
||||
|
||||
Reference in New Issue
Block a user