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

Support hot-reload for Wechaty events listeners #820

Closed
huan opened this issue Sep 19, 2017 · 4 comments
Closed

Support hot-reload for Wechaty events listeners #820

huan opened this issue Sep 19, 2017 · 4 comments

Comments

@huan
Copy link
Member

huan commented Sep 19, 2017

The API might add the following new features:

1. addListener

wechaty.on('message', './message-listener')

If the second parameter is a string instead of a function, then we can use func = require('./message-listener') as the listener function, monitor the file, and reload it if the file had been updated.

2. WechatyInstanceOptions

bot = Wechaty.instance({
    listenerDirectory: './listenerDirectory/'    // this is the directory which contains all listeners.
})

Wechaty will scan ./listenerDirectory/ for the files that the same name as the event, then require it and add it as the listener.


See Also

  1. https://github.com/fastest963/require-reload
  2. http://blog.chatie.io/developer/2017/03/20/added-hot-reload-for-bots.html
  3. https://blogs.msdn.microsoft.com/typescript/2017/06/12/announcing-typescript-2-4-rc/
  4. https://www.youtube.com/watch?v=cGqfM6huJCs
  5. Getting the stack trace in a structured form
  6. Get v8 stack traces as an array of CallSite objects.
  7. A node module for enabling a module to determine its caller.
  8. [Design Spec] ESNext import()
  9. Hot module replacement for node.js
  10. Hot reload tool for node.js

CC @Gcaufy

@Gcaufy
Copy link
Contributor

Gcaufy commented Sep 19, 2017

Looks good for me.
There is another way to do it, may be more convenient to the developers.

bot = Wechaty.instance({
    listeners: './listeners'    // this is the directory which contains all listeners.
});
bot.init();

Maybe you can support both.

@huan
Copy link
Member Author

huan commented Oct 1, 2017

@Gcaufy I just published a new NPM module as a Hot Module Reload tool named hot-import at here: https://github.com/zixia/hot-import

It supports TypeScript, please give it a try and let me know what you think. :)

huan added a commit that referenced this issue Oct 2, 2017
* add support to use module filename as listener (#820)

* 0.8.235

* better log

* 0.8.236

* enable Wechaty.on() use relative filename as listener

* 0.8.237

* 0.8.238

* remove unused Loggable

* Hot Module Replacement (HMR) support powered by hot-import (#820)

* 0.8.239
@huan
Copy link
Member Author

huan commented Oct 2, 2017

Landed at v0.8.240.

@huan huan closed this as completed Oct 2, 2017
@huan
Copy link
Member Author

huan commented Nov 6, 2017

Get to know more about the usage of hot-import listener in Wechaty: #923 #935

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

No branches or pull requests

2 participants