https://github.com/kodedninja/choo-shortemit
shortcut access to emit anywhere in your app
https://github.com/kodedninja/choo-shortemit
Last synced: 24 days ago
JSON representation
shortcut access to emit anywhere in your app
- Host: GitHub
- URL: https://github.com/kodedninja/choo-shortemit
- Owner: kodedninja
- Created: 2018-12-08T17:30:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-08T17:40:21.000Z (over 7 years ago)
- Last Synced: 2025-01-02T22:30:25.404Z (over 1 year ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# choo-shortemit
shortcut access to `emit()` anywhere in your app
copy of Jon Gacnik's [choo-shortcache](https://github.com/jongacnik/choo-shortcache)
## Example
```javascript
app.use(require('choo-shortemit'))
```
Anywhere in your application
```javascript
var html = require('choo/html')
var Component = require('nanocomponent')
var { emit } = require('choo-shortemit')
module.exports = class MyComponent extends Component {
createElement() {
return html`
Click me!
`
function onclick(e) {
e.preventDefault()
emit('clicked')
}
}
}
```
## Why?
Sometimes you want to interact directly with the app so you want to call `emit()`, but it's a struggle (and ugly code) to pass it down to the component. This plugin allows you to emit event anywhere in your app. Under the hood it just creates a reference to `emitter.emit()`.