Also, How does the pre-emit hook and post-emit hook work with respect to passing data into the emit event or receiving the leftover data after the componentProp setter functions are processed? Is there a way to cancel the emit propagation if in the pre-emit hook function the application finds something wrong with the data the user has provided?
Actually, in your specific code snippet, the processing there is simply setting custom data, which would be specified in the nuxt.config entry as the "msg":
That msg will get sent with the beep event. If you require custom processing, you do that in the pre-emit hook, and share the data using Vue's data.
With regards to cancelling an emitter event, while it's not currently implemented in the plugin, it would be done by setting a validation flag in the pre-emit hook, and watching that value. When it changes and becomes true, emit the event (i.e., call this.beep).
Actually, I apologize for my answer to the second question. I realize I may have misspoke to quickly and perhaps stated something that could be incorrect. In the current implementation of the plugin, this is what is going on in the emitter:
await runHook(ctx, pre) // run the pre-emit hook
return new Promise((resolve, reject) => {
...
// Emit the event "emitEvt" with msg:
socket.emit(emitEvt, msg, (resp) => {
// Handle response
})
...
})
So, the plugin is currently not checking the return value of the runHook, but I guess the next version can check for a validation value (true or false). If validation fails, the emitter should not emit the event. However, to prevent breaking code for existing users of the plugin, it should only operate on the return value if it's defined (I'll keep thinking about this). The other design challenge is: do I treat the return value as a validation value or as data that should be propagated to the emit "msg"? Maybe some happy combination can be made.
But, back to your question...so for now since the plugin does't check the pre-emit hook's validation value, you would just update your code as follows:
checkBeep() { // You'd still have this method defined
if (this.inputValid) {
// valid input:
this.beep() // "beep" gets emitted with "msg"
}
}
This way, you can still have checkBeep defined, but just omit it from the nuxt.config entry so that the plugin doesn't call it. I know going forward, it will be cleaner to let the plugin do it, so I'll just need some time to think about it. (the challenge is when a lot of people have already downloaded it, there's a small risk I'll break there existing code, so I just have to take that into consideration too)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Also, How does the pre-emit hook and post-emit hook work with respect to passing data into the emit event or receiving the leftover data after the componentProp setter functions are processed? Is there a way to cancel the emit propagation if in the pre-emit hook function the application finds something wrong with the data the user has provided?
Actually, in your specific code snippet, the processing there is simply setting custom data, which would be specified in the nuxt.config entry as the "msg":
That msg will get sent with the beep event. If you require custom processing, you do that in the pre-emit hook, and share the data using Vue's data.
With regards to cancelling an emitter event, while it's not currently implemented in the plugin, it would be done by setting a validation flag in the pre-emit hook, and watching that value. When it changes and becomes true, emit the event (i.e., call
this.beep
).Thank you for all of your replies, Richard. This has set me up well!
Actually, I apologize for my answer to the second question. I realize I may have misspoke to quickly and perhaps stated something that could be incorrect. In the current implementation of the plugin, this is what is going on in the emitter:
So, the plugin is currently not checking the return value of the runHook, but I guess the next version can check for a validation value (true or false). If validation fails, the emitter should not emit the event. However, to prevent breaking code for existing users of the plugin, it should only operate on the return value if it's defined (I'll keep thinking about this). The other design challenge is: do I treat the return value as a validation value or as data that should be propagated to the emit "msg"? Maybe some happy combination can be made.
But, back to your question...so for now since the plugin does't check the pre-emit hook's validation value, you would just update your code as follows:
nuxt.config:
And then in your component.js:
This way, you can still have
checkBeep
defined, but just omit it from the nuxt.config entry so that the plugin doesn't call it. I know going forward, it will be cleaner to let the plugin do it, so I'll just need some time to think about it. (the challenge is when a lot of people have already downloaded it, there's a small risk I'll break there existing code, so I just have to take that into consideration too)