-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat: added wechaty plugin #1946
Conversation
As the discussion here: #1939 I made few changes of the demo code. Just want to make sure you are agree with it. 1. I would like to call it
|
Hi @Gcaufy , Thank you for the design of our powerful Middleware/Plugin system for Wechaty! I have read your questions and also the source code in the PR, I believe we are in the right way to archive our goal. Here's my reply for your 3 questions:
I have no preference between those two names because I feel they are all fit our design. I agree with you that the middleware mostly they are chaining for doing something together, but in our system, it does not. I like the name of "Middleware" coz it sounds more fashion. And the name of "Plugin" is more classic, simple, and clean, so they are all good. Please feel free to make your decision about selecting the name, and I'll support your final choice!
My opinion for the Interface is not to use a Class because it looks heavy. I'd like to purpose the following design, to archive the same goals: export type WechatyPlugin = (...options: any[]) => (wechaty: Wechaty) => void
const kickPlugin: WechatyPlugin = (managedRoomTopic: string) => wechaty => {
wechaty.on('message', message => {
...
})
}
wechaty.use(kickPlugin('My Room Topic')) As my personal feeling, the above So I'd like to purpose that our Plugin interface would be better to be defined as a Functional Interface.
Could you please explain it with more examples about why you want to design like that? I feel it will be more clear and simple if we only provide a I'll also add some comments to the PR code, and please feel free to let me know what you think. Thank you for your design and questions again, and I hope you have a great weekend! |
Here are the conclusions, just want to make sure I'm not missing anything.
btw. I probably need to work this in this weekend. |
src/wechaty.ts
Outdated
abstract installed?: boolean | ||
|
||
export interface WechatyPlugin { | ||
(this: Wechaty): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about let's use an explicit args for passing the wechaty
instead of using this
?
I'll write the reason in detail in the comments outside.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Everything looks good, thank you very much @Gcaufy ! I have one concern about the In my experience in the past years, there are lots of developers who do not understand what They will be very confused about the I personally like to use However, according to what the above screenshot shows out, I'd like to suggest that we use a |
src/wechaty.spec.ts
Outdated
this.on('message', () => (result += 'FROM_MY_PLUGIN:')) | ||
} | ||
} | ||
Wechaty.use(myGlobalPlugin()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class WechatyTest extends Wechaty {}
WechatyTest.use(myGlobalPlugin())
Change this part to the above code would be better because it will not modify the global Wechaty
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
src/wechaty.ts
Outdated
@@ -152,6 +156,8 @@ export class Wechaty extends EventEmitter implements Sayable { | |||
*/ | |||
private static globalInstance: Wechaty | |||
|
|||
private static globalPlugins: WechatyPlugin[] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the variable name style to be consistent, I'd like to suggest to rename the globalPlugins
to globalPluginList
.
I don't like this either. One of the reason to use Class style is to avoid using |
kindly ping @Gcaufy I believe that after we change the I cannot be waiting to use this great new feature! |
Changes:
|
Thanks to this great Plugin system, it will greatly improve the Wechaty ecosystem by letting everyone writing a powerful plugin to archive their needs with ease! This feature will be available from Wechaty version 0.39.19 |
Wechaty.use
Checklist
Description
#1939
We can discuss it here.
Does this PR introduce a breaking change?