Add electron api context

This commit is contained in:
2022-04-15 22:51:38 +08:00
parent 7e4fee3fe5
commit 4f175a5505
11 changed files with 161 additions and 16 deletions
+1 -1
View File
@@ -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) => {
+20
View File
@@ -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 };