跳到主要内容

RxDBPluginTree

Defined in: rxdb-plugin-tree/src/plugin.ts:44

树形结构插件。

Remarks​

只做一件事:把 TreeRepository 登记到 rxdb 的仓储注册表,并声明它撑不住 SyncType.QueryCache。登记是 scoped 的 —— 连接断开时随 scope 一起撤销, 不会把指向已拆纪元的仓储留在 rxdb 上。

四个树查询(findDescendants / countDescendants / findAncestors / countAncestors) 与它们的增量 merge 都挂在 TreeRepository 上,不装本插件的应用连 QueryOptions 里都没有这四支。

一般不直接 new,用工厂 rxDBPluginTree 交给 .use()。

Example​

import { rxDBPluginTree } from '@aiao/rxdb-plugin-tree';

const rxdb = new RxDB({ entities: [Category] }).use(rxDBPluginTree);

Extends​

Implements​

Constructors​

Constructor​

new RxDBPluginTree(rxdb): RxDBPluginTree;

Defined in: rxdb/dist/rxdb-plugin.d.ts:137

Parameters​

ParameterType
rxdbRxDB

Returns​

RxDBPluginTree

Inherited from​

RxDBPluginBase.constructor

Properties​

lifecycle​

readonly lifecycle: "scoped";

Defined in: rxdb-plugin-tree/src/plugin.ts:45

声明本插件已迁移到作用域拆卸。

Remarks​

取值为 'scoped' 时宿主释放完插件作用域就收手,不再调用 IRxDBPlugin.destroy。 双版本插件(既要能装进旧宿主又要能装进新宿主)两样都写:旧宿主不认识本字段、只会走 destroy();新宿主认识,于是只走作用域,两边都不会清理两次。

之所以要显式标记而不是去看 install.length 有没有形参:转译产物、Function.prototype.bind 与压缩器都会改写形参个数,把它当契约会误判。

Implementation of​

IRxDBPlugin.lifecycle


name​

name: Uncapitalize<string> = 'tree';

Defined in: rxdb-plugin-tree/src/plugin.ts:46

插件名,用于日志与宿主侧的错误归因

Implementation of​

IRxDBPlugin.name


rxdb​

protected readonly rxdb: RxDB;

Defined in: rxdb/dist/rxdb-plugin.d.ts:136

Inherited from​

RxDBPluginBase.rxdb

Methods​

install()​

install(scope): void;

Defined in: rxdb-plugin-tree/src/plugin.ts:48

安装插件。

Parameters​

ParameterTypeDescription
scopeLifecycleScope本次连接纪元的插件激活作用域;一次 acquire() 只包一步可能抛错的获取

Returns​

void

Remarks​

抛错(含 Promise reject)视为安装失败:宿主会先把已经登记进 scope 的部分 逆序释放掉,再把原错误传播给 connect()。回滚期间的清理错误只记日志,不会盖掉安装错误。

实现方不写形参不破坏契约——install() 与 install(scope) 同样满足本接口。

Implementation of​

IRxDBPlugin.install