@@ -4,30 +4,34 @@ import { paramsToQuery, toRange } from '../history.service.js';
4
4
import { EVENT_RANGE_CHANGE , EVENT_SEARCH_COMMIT , KNOWN_ACTIONS , OVERSCAN_AMOUNT } from '../constants.js' ;
5
5
import { usePlatformName } from '../types.js' ;
6
6
import { eventToTarget } from '../../../../shared/handlers.js' ;
7
+ import { useContext } from 'preact/hooks' ;
7
8
8
9
// Create the context
9
- const HistoryServiceContext = createContext ( { } ) ;
10
+ const HistoryServiceContext = createContext ( {
11
+ service : /** @type {import("../history.service.js").HistoryService } */ ( { } ) ,
12
+ } ) ;
10
13
11
14
/**
12
15
* Provides a context for the history service, allowing dependent components to access it.
13
16
* Everything that interacts with the service should be registered here
14
17
*
15
18
* @param {Object } props
16
19
* @param {import("../history.service.js").HistoryService } props.service
17
- * @param {import("../history.service.js").ServiceData } props.initial
18
20
* @param {import("preact").ComponentChild } props.children
19
21
*/
20
- export function HistoryServiceProvider ( { service, initial, children } ) {
21
- const platformName = usePlatformName ( ) ;
22
+ export function HistoryServiceProvider ( { service, children } ) {
23
+ return < HistoryServiceContext . Provider value = { { service } } > { children } </ HistoryServiceContext . Provider > ;
24
+ }
22
25
26
+ export function useGlobalHandlers ( ) {
27
+ const { service } = useContext ( HistoryServiceContext ) ;
28
+ const platformName = usePlatformName ( ) ;
23
29
useSearchCommit ( service ) ;
24
30
useRangeChange ( service ) ;
25
31
useLinkClickHandler ( service , platformName ) ;
26
32
useButtonClickHandler ( service ) ;
27
33
useAuxClickHandler ( service , platformName ) ;
28
34
useContextMenu ( service ) ;
29
-
30
- return < HistoryServiceContext . Provider value = { { service, initial } } > { children } </ HistoryServiceContext . Provider > ;
31
35
}
32
36
33
37
/**
0 commit comments