Emit can't handle more than 1 parameter in views
See original GitHub issueExpected behavior
This code (view) should work
function someView (state, emit) {
return html`
<body>
<p>Send something through sockets:</p>
<input id="message" />
<button onclick=${onclick}>Send</button>
</body>
`
function onclick () {
emit('ws:send', document.getElementById('message').value, id)
document.getElementById('message').value = ''
}
}
Actual behavior
The id
parameter in the ws:send
event is undefined
Steps to reproduce behavior
Put that code in a view
This issue is only related to the way choo handle views, it is not related to nanobus. this can be checked running the same example in a store instead of a view, in the store, id is defined. This seems to be due to this code, here route handlers (views) are being called with a eventName
and a single data
parameter.
edit: I guess we could simply change this
var res = handler(self.state, function (eventName, data) {
self.emitter.emit(eventName, data)
})
to this
var res = handler(self.state, self.emitter.emit)
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How pass 2 parameters to EventEmitter in Angular?
I'd ideally want the function that takes the emitted event to force a object of two strings to be received, rather than a...
Read more >Emit function parameters (Client and Server) do not mirror ...
When running tests I am running into an issue were the API for mock-socket's emit function is not aligned with Socket.io's emit function....
Read more >Vue → How to send multiple parameters to :on-change event ...
The reason I couldn't send more than one parameter was because the way that Vue defaults to sending the data on a event...
Read more >A Guide to Vue $emit - How to Emit Custom Events in Vue
How does Vue Emit Work? When we emit an event, we invoke a method with one or more arguments: eventName: string – the...
Read more >How To Pass Data Between Components In Vue.js
Sharing data across components is one of the core functionalities of VueJS. It allows you to design a more modular project, control data ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not clear why it should support a single argument. Also, it’s not the way other event emitter work, e.g. Node EventEmitter
Maybe nanobus docs notation is unclear, it should be like
bus.emit(eventName, […data])
Fixed in
v6.6.1
🎉