question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Emit can't handle more than 1 parameter in views

See original GitHub issue

Expected 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:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
YerkoPalmacommented, Dec 28, 2017

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])

0reactions
yoshuawuytscommented, Dec 28, 2017

Fixed in v6.6.1 🎉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found