<NME> index.ts
<BEF> export * from './components/Menu';
export * from './components/Item';
export { Separator } from './components/Separator';
export { IconFont } from './components/IconFont';
export { Submenu } from './components/Submenu';
export { MenuProvider } from './components/MenuProvider';

export { contextMenu } from './utils/contextMenu';
export { theme, animation } from './utils/styles';

<MSG> rewrite event manager

<DFF> @@ -3,7 +3,6 @@ export { Item } from './components/Item';
 export { Separator } from './components/Separator';
 export { IconFont } from './components/IconFont';
 export { Submenu } from './components/Submenu';
-export { MenuProvider } from './components/MenuProvider';
 
 export { contextMenu } from './utils/contextMenu';
 export { theme, animation } from './utils/styles';

{'commit': "diff --git a/src/components/Menu.tsx b/src/components/Menu.tsx\nindex 71c821d..ea2e35b 100644\n--- a/src/components/Menu.tsx\n+++ b/src/components/Menu.tsx\n@@ -7,7 +7,7 @@ import { Portal } from './Portal';\n \n import { HIDE_ALL, DISPLAY_MENU } from '../utils/actions';\n import { styles } from '../utils/styles';\n-import { eventManager } from '../utils/eventManager';\n+import { eventManager } from '../core/eventManager';\n import { TriggerEvent, StyleProps, MenuId } from '../types';\n import { usePrevious } from '../hooks';\n \n@@ -117,7 +117,6 @@ export const Menu: React.FC<MenuProps> = ({\n     propsFromTrigger: {},\n   });\n   const nodeRef = useRef<HTMLDivElement>(null);\n-  const unsub = useRef<(() => boolean)[]>([]).current;\n   const didMount = useRef(false);\n   const wasVisible = usePrevious(state.visible);\n \n@@ -128,12 +127,12 @@ export const Menu: React.FC<MenuProps> = ({\n   }, [state.visible, onHidden, onShown]);\n \n   useEffect(() => {\n-    unsub.push(eventManager.on(DISPLAY_MENU(id), show));\n-    unsub.push(eventManager.on(HIDE_ALL, hide));\n     didMount.current = true;\n \n+    eventManager.on(DISPLAY_MENU(id), show).on(HIDE_ALL, hide);\n+\n     return () => {\n-      unsub.forEach(cb => cb());\n+      eventManager.off(DISPLAY_MENU(id), show).off(HIDE_ALL, hide);\n     };\n   }, []);\n \n@@ -179,16 +178,15 @@ export const Menu: React.FC<MenuProps> = ({\n     }\n   }\n \n-  function show(e: TriggerEvent, props: object) {\n-    e.stopPropagation();\n-    eventManager.emit(HIDE_ALL);\n-    const { x, y } = getMousePosition(e);\n+  function show({ event, props }: { event: TriggerEvent; props: object }) {\n+    event.stopPropagation();\n+    const { x, y } = getMousePosition(event);\n \n     setState({\n       visible: true,\n       x,\n       y,\n-      nativeEvent: e,\n+      nativeEvent: event,\n       propsFromTrigger: props,\n     });\n   }\ndiff --git a/src/core/eventManager.ts b/src/core/eventManager.ts\nnew file mode 100644\nindex 0000000..cff6369\n--- /dev/null\n+++ b/src/core/eventManager.ts\n@@ -0,0 +1,35 @@\n+export type EventType = string | number | symbol;\n+export type Handler<T = any> = (args: T) => void;\n+\n+export interface EventManager<E = EventType> {\n+  on<T = any>(event: E, handler: Handler<T>): EventManager<E>;\n+  off<T = any>(event: E, handler?: Handler<T>): EventManager<E>;\n+  emit<T = any>(event: E, args?: T): EventManager<E>;\n+}\n+\n+function createEventManager<E = EventType>(): EventManager<E> {\n+  const eventList = new Map<E, Set<Handler>>();\n+\n+  return {\n+    on<T = any>(event: E, handler: Handler<T>) {\n+      //eslint-disable-next-line @typescript-eslint/no-unused-expressions\n+      eventList.has(event)\n+        ? eventList.get(event)?.add(handler)\n+        : eventList.set(event, new Set([handler]));\n+      return this;\n+    },\n+    off<T = any>(event: E, handler?: Handler<T>) {\n+      handler ? eventList.get(event)!.delete(handler) : eventList.delete(event);\n+      return this;\n+    },\n+    emit<T = any>(event: E, args: T) {\n+      eventList.has(event) &&\n+        eventList.get(event)!.forEach((handler: Handler<T>) => {\n+          handler(args);\n+        });\n+      return this;\n+    },\n+  };\n+}\n+\n+export const eventManager = createEventManager();\ndiff --git a/src/core/index.ts b/src/core/index.ts\nnew file mode 100644\nindex 0000000..7a44402\n--- /dev/null\n+++ b/src/core/index.ts\n@@ -0,0 +1 @@\n+export * from './eventManager';\ndiff --git a/src/index.ts b/src/index.ts\nindex 686165d..926e96b 100644\n--- a/src/index.ts\n+++ b/src/index.ts\n@@ -3,7 +3,6 @@ export { Item } from './components/Item';\n export { Separator } from './components/Separator';\n export { IconFont } from './components/IconFont';\n export { Submenu } from './components/Submenu';\n-export { MenuProvider } from './components/MenuProvider';\n \n export { contextMenu } from './utils/contextMenu';\n export { theme, animation } from './utils/styles';\ndiff --git a/src/utils/contextMenu.ts b/src/utils/contextMenu.ts\nindex 632d8d1..4cad775 100644\n--- a/src/utils/contextMenu.ts\n+++ b/src/utils/contextMenu.ts\n@@ -1,4 +1,4 @@\n-import { eventManager } from './eventManager';\n+import { eventManager } from '../core/eventManager';\n import { HIDE_ALL, DISPLAY_MENU } from './actions';\n import { MenuId } from '../types';\n import React, { SyntheticEvent } from 'react';\n@@ -13,12 +13,11 @@ export interface ContextMenu {\n }\n \n const contextMenu: ContextMenu = {\n-  show({ id, event, props }) {\n-    eventManager.emit(\n-      DISPLAY_MENU(id),\n-      (event as SyntheticEvent).nativeEvent || event,\n-      props\n-    );\n+  show({ id, event, props = {} }) {\n+    eventManager.emit(HIDE_ALL).emit(DISPLAY_MENU(id), {\n+      event: (event as SyntheticEvent).nativeEvent || event,\n+      props,\n+    });\n   },\n   hideAll() {\n     eventManager.emit(HIDE_ALL);\ndiff --git a/src/utils/eventManager.ts b/src/utils/eventManager.ts\ndeleted file mode 100644\nindex 3fcb1dc..0000000\n--- a/src/utils/eventManager.ts\n+++ /dev/null\n@@ -1,31 +0,0 @@\n-type Callback = (...args: any) => void;\n-type EventId = number | string;\n-\n-interface EventManager {\n-  eventList: Map<EventId, Set<Callback>>;\n-  on: (event: EventId, callback: Callback) => () => boolean;\n-  emit: (event: EventId, ...args: any) => boolean;\n-}\n-\n-const eventManager: EventManager = {\n-  eventList: new Map(),\n-  on(event, callback) {\n-    this.eventList.has(event) || this.eventList.set(event, new Set());\n-    this.eventList.get(event)!.add(callback);\n-\n-    return () => this.eventList.get(event)!.delete(callback);\n-  },\n-  emit(event, ...args) {\n-    if (!this.eventList.has(event)) {\n-      console.warn(\n-        `<${event}> Event is not registered. Did you forgot to bind the event ?`\n-      );\n-      return false;\n-    }\n-    this.eventList.get(event)!.forEach(cb => cb.call(this, ...args));\n-\n-    return true;\n-  },\n-};\n-\n-export { eventManager };\n", 'commit_subject': 'rewrite event manager', 'repo_name': 'fkhadra/react-contexify', 'committer': {'name': 'Fadi', 'email': 'fe880fa64550e16b4d4d7f97877aeccc87bc9611@gmail.com', 'time_sec': '1602017416', 'tz_offset': '120', 'date': {'seconds': '1602017416'}}, 'commit_tree': '02878cd9b3d0427d3b8c1886c7ef67c3c2336a45', 'commit_message': 'rewrite event manager\n', 'language_name': 'HTML', 'license': 'mit', 'hunks': "@@ -3,7 +3,6 @@ export { Item } from './components/Item';\n export { Separator } from './components/Separator';\n export { IconFont } from './components/IconFont';\n export { Submenu } from './components/Submenu';\n-export { MenuProvider } from './components/MenuProvider';\n \n export { contextMenu } from './utils/contextMenu';\n export { theme, animation } from './utils/styles';\n", 'addition_count': 0, 'deletion_count': 1, 'src_file': 'a/src/index.ts', 'tgt_file': 'b/src/index.ts', 'file_extension': '.ts', 'before_file': "export * from './components/Menu';\nexport * from './components/Item';\nexport { Separator } from './components/Separator';\nexport { IconFont } from './components/IconFont';\nexport { Submenu } from './components/Submenu';\nexport { MenuProvider } from './components/MenuProvider';\n\nexport { contextMenu } from './utils/contextMenu';\nexport { theme, animation } from './utils/styles';\n", 'message': 'rewrite event manager\n', 'author_name': 'Fadi', 'lang': 'ts'}