enhance(event):加入事件总线。
This commit is contained in:
parent
7aca83b203
commit
a1ea3c8414
5
src/EventBus.ts
Normal file
5
src/EventBus.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { createContext } from 'react';
|
||||
|
||||
export const eventBus = new EventEmitter();
|
||||
export const EventBusContext = createContext<EventEmitter>(eventBus);
|
15
src/main.tsx
15
src/main.tsx
@ -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>
|
||||
);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user