Commit 195214d9 authored by nanahira's avatar nanahira

add more filter decorators and doc update

parent effef813
...@@ -760,6 +760,9 @@ export default class MyPlugin extends StarterPlugin(Config) { ...@@ -760,6 +760,9 @@ export default class MyPlugin extends StarterPlugin(Config) {
- `@OnPlatform(value)` 等价于 `ctx.platform(value)` - `@OnPlatform(value)` 等价于 `ctx.platform(value)`
- `@OnPrivate(value)` 等价于 `ctx.private(value)` - `@OnPrivate(value)` 等价于 `ctx.private(value)`
- `@OnSelection(value)` 等价于 `ctx.select(value)` - `@OnSelection(value)` 等价于 `ctx.select(value)`
- `@OnUnion(value)` 等价于 `ctx.union(value)`
- `@OnIntersect(value)` 等价于 `ctx.intersect(value)`
- `@OnExclude(value)` 等价于 `ctx.exclude(value)`
## 插值定义 ## 插值定义
...@@ -1159,6 +1162,27 @@ export class MyPluginBar extends FooPlugin(BarConfig) { ...@@ -1159,6 +1162,27 @@ export class MyPluginBar extends FooPlugin(BarConfig) {
koishi-thirdeye 也提供了一些开箱即用的插件模板,这些模板可以帮助您简单地对各个子插件进行有效的组织。事实上,上面的 [`StarterPlugin`](#插件基类) 就是内置模板的一种。 koishi-thirdeye 也提供了一些开箱即用的插件模板,这些模板可以帮助您简单地对各个子插件进行有效的组织。事实上,上面的 [`StarterPlugin`](#插件基类) 就是内置模板的一种。
#### HttpClientPlugin
HttpClientPlugin 是一个内置的模板,里面提供了一个 `http` 成员变量,可以用于发送 HTTP 请求。该模板内置了相关 http 的配置以让插件的用户定义 `this.http` 相关的行为。
```ts
@RegisterSchema()
export class Config {
@SchemaProperty()
foo: string
// 将被增加 headers, proxyAgent, timeout 等配置
}
@DefinePlugin()
export class MyPlugin extends HttpClientPlugin(Config) {
@UseCommand('foo')
onFoo() {
return this.http.get('https://example.com')
}
}
```
#### 组合插件 #### 组合插件
使用组合插件可以将多个插件组合成一个插件,并将子插件的配置映射到插件配置的某一个元素中。在父插件中可以使用 `getInstance(name)` 方法获取子插件的实例。 使用组合插件可以将多个插件组合成一个插件,并将子插件的配置映射到插件配置的某一个元素中。在父插件中可以使用 `getInstance(name)` 方法获取子插件的实例。
......
...@@ -28,6 +28,9 @@ export const { ...@@ -28,6 +28,9 @@ export const {
OnPlatform, OnPlatform,
OnPrivate, OnPrivate,
OnSelection, OnSelection,
OnUnion,
OnIntersect,
OnExclude,
} = koishiRegistrar.selectorDecorators(); } = koishiRegistrar.selectorDecorators();
export const { export const {
......
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
Next, Next,
Session, Session,
Component, Component,
Filter,
} from 'koishi'; } from 'koishi';
import { CanBeObserved, sessionRxToPromise } from './utility/rxjs-session'; import { CanBeObserved, sessionRxToPromise } from './utility/rxjs-session';
import { import {
...@@ -250,6 +251,15 @@ export class KoishiRegistrar extends Registrar<Context> { ...@@ -250,6 +251,15 @@ export class KoishiRegistrar extends Registrar<Context> {
OnSelection: this.decorateTransformer((ctx, selection: Selection) => OnSelection: this.decorateTransformer((ctx, selection: Selection) =>
selectContext(ctx, selection), selectContext(ctx, selection),
), ),
OnUnion: this.decorateTransformer((ctx, arg: Filter | Context) =>
ctx.union(arg),
),
OnIntersect: this.decorateTransformer((ctx, arg: Filter | Context) =>
ctx.intersect(arg),
),
OnExclude: this.decorateTransformer((ctx, arg: Filter | Context) =>
ctx.exclude(arg),
),
}; };
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment