MCPcopy
hub / github.com/vuejs/core / on

Function on

packages/runtime-core/src/compat/instanceEventEmitter.ts:26–47  ·  view source on GitHub ↗
(
  instance: ComponentInternalInstance,
  event: string | string[],
  fn: Function,
)

Source from the content-addressed store, hash-verified

24}
25
26export function on(
27 instance: ComponentInternalInstance,
28 event: string | string[],
29 fn: Function,
30): ComponentPublicInstance | null {
31 if (isArray(event)) {
32 event.forEach(e => on(instance, e, fn))
33 } else {
34 if (event.startsWith('hook:')) {
35 assertCompatEnabled(
36 DeprecationTypes.INSTANCE_EVENT_HOOKS,
37 instance,
38 event,
39 )
40 } else {
41 assertCompatEnabled(DeprecationTypes.INSTANCE_EVENT_EMITTER, instance)
42 }
43 const events = getRegistry(instance)
44 ;(events[event] || (events[event] = [])).push(fn)
45 }
46 return instance.proxy
47}
48
49export function once(
50 instance: ComponentInternalInstance,

Callers 1

onceFunction · 0.70

Calls 4

assertCompatEnabledFunction · 0.90
getRegistryFunction · 0.85
forEachMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected