Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

respond() doesn't take a function as its data argument #16

Closed
steph643 opened this issue Mar 19, 2019 · 3 comments
Closed

respond() doesn't take a function as its data argument #16

steph643 opened this issue Mar 19, 2019 · 3 comments

Comments

@steph643
Copy link

In the source code, respond() is advertised as being able to take a function as its data argument:

/**
   *  A convience method for listening to an event and then responding with some data
   *  right away. Automatically removes the listener
   ...
   *  @param {Object} [data = {}] The object to pass back.
   *  	May also be a function; the return value will be sent as data in this case.
   ...
   */
respond(event, data = {}, runOnce = false) 

But it doesn't work. Only plain objects are supported.

This is too bad, as doing some dynamic computation before sending the data back is often required.

@steph643
Copy link
Author

steph643 commented Mar 19, 2019

Workaround: return a plain object with one field initialized with a function call.

bellhop.respond('init', {
  myData: (() => {
    // Computation here
    ...
    return result
  })()
})

@chipbell4
Copy link
Contributor

You're absolutely right. This probably should be a feature, and it looks like we intended to but forgot. We'll get that knocked out shortly and release a 2.4.0

@chipbell4
Copy link
Contributor

This should be resolved now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants