diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_controller.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_controller.ts index 6d3050d88a..853bc2f006 100644 --- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_controller.ts +++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_controller.ts @@ -1,6 +1,5 @@ import { CellIdentifier } from './cell_bd_svc'; import { CellCache, CellCacheKey } from './cell_cache'; -import { FieldController } from '../field/field_controller'; import { CellDataLoader } from './data_parser'; import { CellDataPersistence } from './data_persistence'; import { FieldBackendService, TypeOptionParser } from '../field/field_bd_svc'; @@ -112,21 +111,24 @@ export class CellController { } class CellDataNotifier extends ChangeNotifier { - _cellData: T | null; + _cellData: Option; constructor(cellData: T) { super(); - this._cellData = cellData; + this._cellData = Some(cellData); } - set cellData(data: T | null) { + set cellData(data: Option) { if (this._cellData !== data) { this._cellData = data; - this.notify(this._cellData); + + if (this._cellData.some) { + this.notify(this._cellData.val); + } } } - get cellData(): T | null { + get cellData(): Option { return this._cellData; } } diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_parser.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_parser.ts index e44867c0df..20a7a3e68d 100644 --- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_parser.ts +++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_parser.ts @@ -3,11 +3,11 @@ import { CellBackendService, CellIdentifier } from './cell_bd_svc'; import { DateCellDataPB } from '../../../../../services/backend/models/flowy-database/date_type_option_entities'; import { SelectOptionCellDataPB } from '../../../../../services/backend/models/flowy-database/select_type_option'; import { URLCellDataPB } from '../../../../../services/backend/models/flowy-database/url_type_option_entities'; -import { Err, Ok } from 'ts-results'; +import { Err, None, Ok, Option, Some } from 'ts-results'; import { Log } from '../../../../utils/log'; abstract class CellDataParser { - abstract parserData(data: Uint8Array): T; + abstract parserData(data: Uint8Array): Option; } class CellDataLoader { @@ -34,32 +34,32 @@ export const utf8Decoder = new TextDecoder('utf-8'); export const utf8Encoder = new TextEncoder(); class StringCellDataParser extends CellDataParser { - parserData(data: Uint8Array): string { - return utf8Decoder.decode(data); + parserData(data: Uint8Array): Option { + return Some(utf8Decoder.decode(data)); } } class DateCellDataParser extends CellDataParser { - parserData(data: Uint8Array): DateCellDataPB { - return DateCellDataPB.deserializeBinary(data); + parserData(data: Uint8Array): Option { + return Some(DateCellDataPB.deserializeBinary(data)); } } -class SelectOptionCellDataParser extends CellDataParser { - parserData(data: Uint8Array): SelectOptionCellDataPB | undefined { +class SelectOptionCellDataParser extends CellDataParser { + parserData(data: Uint8Array): Option { if (data.length === 0) { - return undefined; + return None; } - return SelectOptionCellDataPB.deserializeBinary(data); + return Some(SelectOptionCellDataPB.deserializeBinary(data)); } } -class URLCellDataParser extends CellDataParser { - parserData(data: Uint8Array): URLCellDataPB | undefined { +class URLCellDataParser extends CellDataParser { + parserData(data: Uint8Array): Option { if (data.length === 0) { - return undefined; + return None; } - return URLCellDataPB.deserializeBinary(data); + return Some(URLCellDataPB.deserializeBinary(data)); } }