Skip to content

Commit 5249e29

Browse files
authored
Merge pull request #35 from charlesLoder/issue-25/update-plugin-provider
Update the update_plugin_provider method and docs
2 parents b7c5f38 + 7dbb0d4 commit 5249e29

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

src/plugin/base_provider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ export abstract class BaseProvider {
6363
/**
6464
* Update the Plugin state with the current provider.
6565
*/
66-
protected update_plugin_provider(provider: BaseProvider) {
66+
protected update_plugin_provider() {
6767
this.dispatch({
6868
type: "updateProvider",
69-
provider,
69+
provider: this,
7070
});
7171
}
7272

src/providers/userTokenProvider/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class UserTokenProvider extends BaseProvider {
291291
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
292292
e.preventDefault();
293293
this.user_token = inputValue.trim();
294-
this.update_plugin_provider(this);
294+
this.update_plugin_provider();
295295
};
296296

297297
if (!modelProvider) {

stories/docs/creating-a-provider.mdx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To create a custom provider, we need to extend the `BaseProvider` class.
1818

1919
This class provides the necessary methods and properties to interact with Clover AI.
2020

21-
```typescript
21+
```tsx
2222
// my-custom-provider.tsx
2323
import { BaseProvider } from "clover-ai";
2424

@@ -66,11 +66,8 @@ export class MyCustomProvider extends BaseProvider {
6666
const handleClick = () => {
6767
this.#user_accepted = true;
6868

69-
// dispatch a message to Clover AI updating the provider with the new status
70-
this.dispatch({
71-
type: "updateProvider",
72-
provider: this,
73-
});
69+
// update the Plugin state with the modified provider
70+
this.update_plugin_provider();
7471
};
7572

7673
return (
@@ -88,7 +85,7 @@ export class MyCustomProvider extends BaseProvider {
8885

8986
The provider class has access to the plugin's `dispatch` method, which allows it to send messages to Clover AI.
9087

91-
When the user clicks the button, we set `#user_accepted` to `true` and dispatch an `updateProvider` message to Clover AI with the updated provider instance.
88+
When the user clicks the button, we set `#user_accepted` to `true` and update the plugin state with the modified provider using `this.update_plugin_provider()`.
9289

9390
This will trigger Clover AI to re-render the provider with the new status.
9491

@@ -120,7 +117,7 @@ export class MyCustomProvider extends BaseProvider {
120117
const handleClick = () => {
121118
this.#user_accepted = true;
122119
// update the Plugin state with the modified provider
123-
this.update_plugin_provider(this);
120+
this.update_plugin_provider();
124121
};
125122

126123
return (

0 commit comments

Comments
 (0)