Skip to content

Commit b0df240

Browse files
committed
adjust event handler ids to avoid id collisions
1 parent be2508f commit b0df240

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/DailyProvider.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ export const DailyProvider: React.FC<React.PropsWithChildren<Props>> = ({
5050
const handleEvent = useCallback((ev: DailyEventObject) => {
5151
if (!('action' in ev)) return;
5252
const event = ev.action as DailyEvent;
53-
const sortedHandlers = Array.from(eventsMap.current?.[event] ?? []).sort(
54-
(a, b) => a[0] - b[0]
55-
);
53+
const allHandlers = Array.from(eventsMap.current?.[event] ?? []);
54+
const priorityHandlers = allHandlers.filter(([key]) => key < 0);
55+
const normalHandlers = allHandlers.filter(([key]) => key > 0);
56+
const sortedHandlers = [...priorityHandlers, ...normalHandlers];
5657
for (let [, cb] of sortedHandlers) {
5758
cb(ev);
5859
}

src/hooks/useDailyEvent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import { DailyEventContext } from '../DailyEventContext';
1212

1313
type EventCallback<T extends DailyEvent> = (event: DailyEventObject<T>) => void;
1414

15-
let priorityCounter = 0;
16-
export const getPriorityUnique = () => priorityCounter++;
17-
let uniqueCounter = 1000000;
15+
let priorityCounter = -1;
16+
export const getPriorityUnique = () => priorityCounter--;
17+
let uniqueCounter = 1;
1818
export const getUnique = () => uniqueCounter++;
1919

2020
/**

0 commit comments

Comments
 (0)