enhance(event):加入事件总线。

This commit is contained in:
徐涛 2023-03-08 16:49:55 +08:00
parent 7aca83b203
commit a1ea3c8414
2 changed files with 14 additions and 6 deletions

5
src/EventBus.ts Normal file
View File

@ -0,0 +1,5 @@
import { EventEmitter } from 'events';
import { createContext } from 'react';
export const eventBus = new EventEmitter();
export const EventBusContext = createContext<EventEmitter>(eventBus);

View File

@ -3,6 +3,7 @@ import { useColorScheme } from '@mantine/hooks';
import { Notifications } from '@mantine/notifications';
import React, { FC, useState } from 'react';
import ReactDOM from 'react-dom/client';
import { eventBus, EventBusContext } from './EventBus';
import { MainLayout } from './MainLayout';
import { useAppTheme } from './theme';
@ -13,12 +14,14 @@ const AppMain: FC = () => {
return (
<React.StrictMode>
<ColorSchemeProvider colorScheme={colorScheme} toggleColorScheme={setColorScheme}>
<MantineProvider theme={theme} withGlobalStyles withNormalizeCSS>
<Notifications position="bottom-right" limit={5} zIndex={999} />
<MainLayout />
</MantineProvider>
</ColorSchemeProvider>
<EventBusContext.Provider value={eventBus}>
<ColorSchemeProvider colorScheme={colorScheme} toggleColorScheme={setColorScheme}>
<MantineProvider theme={theme} withGlobalStyles withNormalizeCSS>
<Notifications position="bottom-right" limit={5} zIndex={999} />
<MainLayout />
</MantineProvider>
</ColorSchemeProvider>
</EventBusContext.Provider>
</React.StrictMode>
);
};