Skip to content

Letoderea 0.6.0

Latest
Compare
Choose a tag to compare
@RF-Tar-Railt RF-Tar-Railt released this 27 May 06:53
· 20 commits to main since this release
  1. 订阅者函数的参数类型现在支持使用 Annotated 来便捷注入 provider:
    async def _(
        a: int,  # Need Provider
        b: Annotated[str, "index"],  # will generate provider which fetch "index" from ctx
        c: Annotated[float, lambda ctx: ctx["foo"]]  # will generate provider which fetch "foo" from ctx
    ): ...
  2. 增加 bypass_if 便捷装饰器, 用来注入一条件判断的辅助器:
    from arclet.letoderea import bypass_if
    ....
    @bypass_if(lambda ctx: not isinstance(ctx["event"], A))  # subscriber will pass when event is not A
    async def _(): ...
  3. 增加 deref 函数, 用来生成获取事件属性,或比较事件属性是否符号条件的 predicate, 并给如 bypass_if , Annotated , provide 使用
    from arclet.letoderea.ref import deref, generate
    ...
    @dataclass
    class A:
        text: str
    
    print(deref(A).text)  # {'text': None}
    print(deref(A).text == "123")  # {'text': <function Deref.__eq__.<locals>.<lambda>>}
    print(
        generate(deref(A).text == "123")(  # True
            {"event": A(text="123")}
        )
    )
  4. 增加 make_event 装饰器, 用来自动注入 gather 方法
  5. 依赖注入可以根据参数名直接从事件中尝试获取对应参数
  6. Publisher.publish 现在不经过事件系统,直接分发给自身的订阅者
  7. depend_handler 的第二个参数现在可以接受已存在的 contexts