Skip to content

Commit

Permalink
fix: remove process.env #174
Browse files Browse the repository at this point in the history
  • Loading branch information
fkhadra committed Nov 3, 2022
1 parent 4078108 commit 6071e93
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
18 changes: 3 additions & 15 deletions src/core/eventManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { EVENT } from '../constants';

export type EventType = string | number | symbol;
export type Handler<T = any> = (args: T) => void;

Expand All @@ -16,25 +14,15 @@ function createEventManager<E = EventType>(): EventManager<E> {
on<T = any>(event: E, handler: Handler<T>) {
//eslint-disable-next-line @typescript-eslint/no-unused-expressions
eventList.has(event)
? eventList.get(event)?.add(handler)
? eventList.get(event)!.add(handler)
: eventList.set(event, new Set([handler]));
return this;
},
off<T = any>(event: E, handler?: Handler<T>) {
handler ? eventList.get(event)!.delete(handler) : eventList.delete(event);
off<T = any>(event: E, handler: Handler<T>) {
eventList.has(event) && eventList.get(event)!.delete(handler);
return this;
},
emit<T = any>(event: E, args: T) {
if (process.env.NODE !== 'production') {
const currentEv = (event as unknown) as number;

if (!eventList.has(event) && currentEv !== EVENT.HIDE_ALL) {
console.error(
`It seems that the menu you are trying to display is not renderer or you have a menu id mismatch.`,
`You used the menu id: ${event}`
);
}
}
eventList.has(event) &&
eventList.get(event)!.forEach((handler: Handler<T>) => {
handler(args);
Expand Down
6 changes: 0 additions & 6 deletions src/hooks/useContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ export type UseContextMenuProps = Partial<
export function useContextMenu(props?: UseContextMenuProps) {
return {
show(event: TriggerEvent, params?: Omit<ContextMenuParams, 'event'>) {
if (process.env.NODE_ENV === 'development') {
if (!props?.id && !params?.id)
console.error(
"You need to provide an id when initializing the hook `useContextMenu({ id: 'your id' })` or when you display the menu `show(e, { id: 'your id' })`. The later is used to override the one defined during initialization."
);
}
contextMenu.show({
id: (params?.id || props?.id) as string,
props: params?.props || props?.props,
Expand Down

0 comments on commit 6071e93

Please sign in to comment.