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 { Notifications } from '@mantine/notifications';
|
||||||
import React, { FC, useState } from 'react';
|
import React, { FC, useState } from 'react';
|
||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from 'react-dom/client';
|
||||||
|
import { eventBus, EventBusContext } from './EventBus';
|
||||||
import { MainLayout } from './MainLayout';
|
import { MainLayout } from './MainLayout';
|
||||||
import { useAppTheme } from './theme';
|
import { useAppTheme } from './theme';
|
||||||
|
|
||||||
@ -13,12 +14,14 @@ const AppMain: FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<ColorSchemeProvider colorScheme={colorScheme} toggleColorScheme={setColorScheme}>
|
<EventBusContext.Provider value={eventBus}>
|
||||||
<MantineProvider theme={theme} withGlobalStyles withNormalizeCSS>
|
<ColorSchemeProvider colorScheme={colorScheme} toggleColorScheme={setColorScheme}>
|
||||||
<Notifications position="bottom-right" limit={5} zIndex={999} />
|
<MantineProvider theme={theme} withGlobalStyles withNormalizeCSS>
|
||||||
<MainLayout />
|
<Notifications position="bottom-right" limit={5} zIndex={999} />
|
||||||
</MantineProvider>
|
<MainLayout />
|
||||||
</ColorSchemeProvider>
|
</MantineProvider>
|
||||||
|
</ColorSchemeProvider>
|
||||||
|
</EventBusContext.Provider>
|
||||||
</React.StrictMode>
|
</React.StrictMode>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user