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

Function off

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

Source from the content-addressed store, hash-verified

61}
62
63export function off(
64 instance: ComponentInternalInstance,
65 event?: string | string[],
66 fn?: Function,
67): ComponentPublicInstance | null {
68 assertCompatEnabled(DeprecationTypes.INSTANCE_EVENT_EMITTER, instance)
69 const vm = instance.proxy
70 // all
71 if (!event) {
72 eventRegistryMap.set(instance, Object.create(null))
73 return vm
74 }
75 // array of events
76 if (isArray(event)) {
77 event.forEach(e => off(instance, e, fn))
78 return vm
79 }
80 // specific event
81 const events = getRegistry(instance)
82 const cbs = events[event!]
83 if (!cbs) {
84 return vm
85 }
86 if (!fn) {
87 events[event!] = undefined
88 return vm
89 }
90 events[event!] = cbs.filter(cb => !(cb === fn || (cb as any).fn === fn))
91 return vm
92}
93
94export function emit(
95 instance: ComponentInternalInstance,

Callers 1

wrappedFunction · 0.70

Calls 5

assertCompatEnabledFunction · 0.90
getRegistryFunction · 0.85
forEachMethod · 0.80
filterMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected