mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 03:56:23 +08:00
feat: add signal for list events
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import type { Workspace } from '@blocksuite/store';
|
||||
|
||||
import type { Apis, Logger, InitialParams, ConfigStore } from './index';
|
||||
import type {
|
||||
Apis,
|
||||
DataCenterSignals,
|
||||
Logger,
|
||||
InitialParams,
|
||||
ConfigStore,
|
||||
} from './index';
|
||||
|
||||
export class BaseProvider {
|
||||
static id = 'base';
|
||||
protected _apis!: Readonly<Apis>;
|
||||
protected _config!: Readonly<ConfigStore>;
|
||||
protected _globalConfig!: Readonly<ConfigStore>;
|
||||
protected _logger!: Logger;
|
||||
protected _signals!: DataCenterSignals;
|
||||
protected _workspace!: Workspace;
|
||||
|
||||
constructor() {
|
||||
@@ -22,8 +28,8 @@ export class BaseProvider {
|
||||
async init(params: InitialParams) {
|
||||
this._apis = params.apis;
|
||||
this._config = params.config;
|
||||
this._globalConfig = params.globalConfig;
|
||||
this._logger = params.logger;
|
||||
this._signals = params.signals;
|
||||
this._workspace = params.workspace;
|
||||
this._logger.enabled = params.debug;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Workspace } from '@blocksuite/store';
|
||||
|
||||
import type { Apis } from '../apis';
|
||||
import type { DataCenterSignals } from '../datacenter';
|
||||
import type { getLogger } from '../index';
|
||||
import type { ConfigStore } from '../store';
|
||||
|
||||
@@ -9,13 +10,13 @@ export type Logger = ReturnType<typeof getLogger>;
|
||||
export type InitialParams = {
|
||||
apis: Apis;
|
||||
config: Readonly<ConfigStore>;
|
||||
globalConfig: Readonly<ConfigStore>;
|
||||
debug: boolean;
|
||||
logger: Logger;
|
||||
signals: DataCenterSignals;
|
||||
workspace: Workspace;
|
||||
};
|
||||
|
||||
export type { Apis, ConfigStore, Workspace };
|
||||
export type { Apis, ConfigStore, DataCenterSignals, Workspace };
|
||||
export type { BaseProvider } from './base.js';
|
||||
export { AffineProvider } from './affine/index.js';
|
||||
export { LocalProvider } from './local/index.js';
|
||||
|
||||
@@ -32,14 +32,19 @@ export class LocalProvider extends BaseProvider {
|
||||
await this._idb.whenSynced;
|
||||
this._logger('Local data loaded');
|
||||
|
||||
await this._globalConfig.set(`list:${this._workspace.room}`, true);
|
||||
this._signals.listAdd.emit({
|
||||
workspace: this._workspace.room,
|
||||
provider: this.id,
|
||||
locally: true,
|
||||
});
|
||||
}
|
||||
|
||||
async clear() {
|
||||
assert(this._workspace.room);
|
||||
await super.clear();
|
||||
await this._blobs.clear();
|
||||
await this._idb?.clearData();
|
||||
await this._globalConfig.delete(`list:${this._workspace.room}`);
|
||||
this._signals.listRemove.emit(this._workspace.room);
|
||||
}
|
||||
|
||||
async destroy(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user