@@ -5,8 +5,10 @@ import {
5
5
type ComputedRef ,
6
6
isRef ,
7
7
inject ,
8
+ type ShallowRef ,
8
9
} from "vue" ;
9
- import type { ObjectEvent } from "ol/Object" ;
10
+ import type BaseObject from "ol/Object" ;
11
+ import type { EventTypes } from "ol/Observable" ;
10
12
11
13
export const COMMON_EVENTS = [ "change" , "error" , "propertychange" ] ;
12
14
@@ -30,29 +32,21 @@ export const FEATURE_EVENTS = [
30
32
"removefeature" ,
31
33
] ;
32
34
33
- // Define a generic type for the event callback
34
- type EventCallback = ( event : ObjectEvent ) => void ;
35
-
36
- // Define the generic type parameter for the OpenLayers feature
37
- type OpenLayersFeature = {
38
- on : ( event : string , callback : EventCallback ) => void ;
39
- un : ( event : string , callback : EventCallback ) => void ;
40
- } & unknown ;
41
-
42
35
// Define the composable function
43
36
export function useOpenLayersEvents (
44
37
feature :
45
- | OpenLayersFeature
46
- | Ref < OpenLayersFeature >
47
- | ComputedRef < OpenLayersFeature > ,
38
+ | BaseObject
39
+ | Ref < BaseObject >
40
+ | ShallowRef < BaseObject >
41
+ | ComputedRef < BaseObject > ,
48
42
eventNames : string [ ] ,
49
43
) {
50
44
const instance = getCurrentInstance ( ) ;
51
45
const globalOptions = inject ( "ol-options" ) ;
52
46
53
47
onMounted ( ( ) => {
54
- [ ...COMMON_EVENTS , ...eventNames ] . forEach ( ( eventName ) => {
55
- let unwrappedFeature : Pick < OpenLayersFeature , "on" > ;
48
+ ( [ ...COMMON_EVENTS , ...eventNames ] as EventTypes [ ] ) . forEach ( ( eventName ) => {
49
+ let unwrappedFeature : Pick < BaseObject , "on" > ;
56
50
57
51
if ( ! isRef ( feature ) ) {
58
52
unwrappedFeature = feature ;
0 commit comments