Add electron api context
This commit is contained in:
@@ -58,7 +58,7 @@ function superConnectWithEvent<C extends Emitter<E>, E extends Record<EventType,
|
||||
}
|
||||
}
|
||||
|
||||
function superConnect<C extends Emitter<any>>(consumer: Consumer<C>, keyName: string) {
|
||||
function superConnect<C>(consumer: Consumer<C>, keyName: string) {
|
||||
return <R extends RenderComponent>(components: R): R => {
|
||||
return ((props: any) => {
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { createContext } from "react";
|
||||
import { superConnect } from "@Context/Context";
|
||||
import { ISimulatorAPI } from "@Electron/SimulatorAPI";
|
||||
|
||||
interface IMixinElectronProps {
|
||||
electron?: ISimulatorAPI;
|
||||
}
|
||||
|
||||
const ElectronContext = createContext<ISimulatorAPI>({} as ISimulatorAPI);
|
||||
|
||||
ElectronContext.displayName = "Electron";
|
||||
const ElectronProvider = ElectronContext.Provider;
|
||||
const ElectronConsumer = ElectronContext.Consumer;
|
||||
|
||||
/**
|
||||
* 修饰器
|
||||
*/
|
||||
const useElectron = superConnect<ISimulatorAPI>(ElectronConsumer, "electron");
|
||||
|
||||
export { useElectron, ElectronProvider, IMixinElectronProps, ISimulatorAPI };
|
||||
Reference in New Issue
Block a user