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
zixia opened this Issue Sep 19, 2017 · 4 comments

Comments

2 participants
@zixia
Member

zixia 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

@zixia zixia added the enhancement label Sep 19, 2017

@Gcaufy

This comment has been minimized.

Show comment
Hide comment
@Gcaufy

Gcaufy Sep 19, 2017

Member

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.

Member

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.

@zixia

This comment has been minimized.

Show comment
Hide comment
@zixia

zixia Oct 1, 2017

Member

@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. :)

Member

zixia 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. :)

zixia added a commit that referenced this issue Oct 2, 2017

Add Hot Listener Support (#820) (#841)
* 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
@zixia

This comment has been minimized.

Show comment
Hide comment
@zixia

zixia Oct 2, 2017

Member

Landed at v0.8.240.

Member

zixia commented Oct 2, 2017

Landed at v0.8.240.

@zixia zixia closed this Oct 2, 2017

@zixia

This comment has been minimized.

Show comment
Hide comment
@zixia

zixia Nov 6, 2017

Member

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

Member

zixia 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