Skip to content

Commit 4797c24

Browse files
LinusBorgThorsten Luenborg
and
Thorsten Luenborg
authored
migration: add example for replacement of eventHub (#846)
Co-authored-by: Thorsten Luenborg <[email protected]>
1 parent f956091 commit 4797c24

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/guide/migration/events-api.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ We removed `$on`, `$off` and `$once` methods from the instance completely. `$emi
5858

5959
## Migration Strategy
6060

61-
Existing event hubs can be replaced by using an external library implementing the event emitter interface, for example [mitt](https://github.com/developit/mitt) or [tiny-emitter](https://github.com/scottcorgan/tiny-emitter).
61+
In Vue 3, it is no longer possible to use these APIs to listen to a component's own emitted events from within a component, there is no migration path for that use case.
6262

63-
These methods can also be supported in compatibility builds.
63+
But the eventHub pattern can be replaced by using an external library implementing the event emitter interface, for example [mitt](https://github.com/developit/mitt) or [tiny-emitter](https://github.com/scottcorgan/tiny-emitter).
64+
65+
Example:
66+
67+
```js
68+
//eventHub.js
69+
import emitter from 'tiny-emitter/instance'
70+
71+
export default {
72+
$on: (...args) => emitter.on(...args),
73+
$once: (...args) => emitter.once(...args),
74+
$off: (...args) => emitter.off(...args),
75+
$emit: (...args) => emitter.emit(...args),
76+
}
77+
```
78+
79+
This provides the same event emitter API as in Vue 2.
80+
81+
These methods may also be supported in a future compatibility build of Vue 3.

0 commit comments

Comments
 (0)