chore: rename class according to gitbook documentation (#1682)

This commit is contained in:
Nathan.fooo 2023-01-12 10:01:17 +08:00 committed by GitHub
parent fe4e28b576
commit 860c5d100b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 82 additions and 74 deletions

View File

@ -64,7 +64,7 @@ class BoardCheckboxCellState with _$BoardCheckboxCellState {
required bool isSelected,
}) = _CheckboxCellState;
factory BoardCheckboxCellState.initial(GridCellController context) {
factory BoardCheckboxCellState.initial(GridTextCellController context) {
return BoardCheckboxCellState(
isSelected: _isSelected(context.getCellData()));
}

View File

@ -60,7 +60,7 @@ class BoardNumberCellState with _$BoardNumberCellState {
required String content,
}) = _BoardNumberCellState;
factory BoardNumberCellState.initial(GridCellController context) =>
factory BoardNumberCellState.initial(GridTextCellController context) =>
BoardNumberCellState(
content: context.getCellData() ?? "",
);

View File

@ -6,7 +6,7 @@ import 'dart:async';
part 'board_text_cell_bloc.freezed.dart';
class BoardTextCellBloc extends Bloc<BoardTextCellEvent, BoardTextCellState> {
final GridCellController cellController;
final GridTextCellController cellController;
void Function()? _onCellChangedFn;
BoardTextCellBloc({
required this.cellController,
@ -71,7 +71,7 @@ class BoardTextCellState with _$BoardTextCellState {
required bool enableEdit,
}) = _BoardTextCellState;
factory BoardTextCellState.initial(GridCellController context) =>
factory BoardTextCellState.initial(GridTextCellController context) =>
BoardTextCellState(
content: context.getCellData() ?? "",
enableEdit: false,

View File

@ -288,7 +288,7 @@ class _BoardContentState extends State<BoardContent> {
rowPB: rowPB,
);
final dataController = GridRowDataController(
final dataController = RowDataController(
rowInfo: rowInfo,
fieldController: fieldController,
rowCache: rowCache,

View File

@ -35,7 +35,7 @@ class _BoardTextCellState extends State<BoardTextCell> {
@override
void initState() {
final cellController =
widget.cellControllerBuilder.build() as GridCellController;
widget.cellControllerBuilder.build() as GridTextCellController;
_cellBloc = BoardTextCellBloc(cellController: cellController)
..add(const BoardTextCellEvent.initial());
_controller = TextEditingController(text: _cellBloc.state.content);

View File

@ -1,15 +1,15 @@
part of 'cell_service.dart';
typedef GridCellController = IGridCellController<String, String>;
typedef GridCheckboxCellController = IGridCellController<String, String>;
typedef GridNumberCellController = IGridCellController<String, String>;
typedef GridTextCellController = GridCellController<String, String>;
typedef GridCheckboxCellController = GridCellController<String, String>;
typedef GridNumberCellController = GridCellController<String, String>;
typedef GridSelectOptionCellController
= IGridCellController<SelectOptionCellDataPB, String>;
= GridCellController<SelectOptionCellDataPB, String>;
typedef GridChecklistCellController
= IGridCellController<SelectOptionCellDataPB, String>;
= GridCellController<SelectOptionCellDataPB, String>;
typedef GridDateCellController
= IGridCellController<DateCellDataPB, CalendarData>;
typedef GridURLCellController = IGridCellController<URLCellDataPB, String>;
= GridCellController<DateCellDataPB, CalendarData>;
typedef GridURLCellController = GridCellController<URLCellDataPB, String>;
abstract class GridCellControllerBuilderDelegate {
GridCellFieldNotifier buildFieldNotifier();
@ -27,7 +27,7 @@ class GridCellControllerBuilder {
}) : _cellCache = cellCache,
_cellId = cellId;
IGridCellController build() {
GridCellController build() {
final cellFieldNotifier = delegate.buildFieldNotifier();
switch (_cellId.fieldType) {
case FieldType.Checkbox:
@ -35,12 +35,12 @@ class GridCellControllerBuilder {
cellId: _cellId,
parser: StringCellDataParser(),
);
return GridCellController(
return GridTextCellController(
cellId: _cellId,
cellCache: _cellCache,
cellDataLoader: cellDataLoader,
fieldNotifier: cellFieldNotifier,
cellDataPersistence: CellDataPersistence(cellId: _cellId),
cellDataPersistence: TextCellDataPersistence(cellId: _cellId),
);
case FieldType.DateTime:
final cellDataLoader = GridCellDataLoader(
@ -67,19 +67,19 @@ class GridCellControllerBuilder {
cellCache: _cellCache,
cellDataLoader: cellDataLoader,
fieldNotifier: cellFieldNotifier,
cellDataPersistence: CellDataPersistence(cellId: _cellId),
cellDataPersistence: TextCellDataPersistence(cellId: _cellId),
);
case FieldType.RichText:
final cellDataLoader = GridCellDataLoader(
cellId: _cellId,
parser: StringCellDataParser(),
);
return GridCellController(
return GridTextCellController(
cellId: _cellId,
cellCache: _cellCache,
cellDataLoader: cellDataLoader,
fieldNotifier: cellFieldNotifier,
cellDataPersistence: CellDataPersistence(cellId: _cellId),
cellDataPersistence: TextCellDataPersistence(cellId: _cellId),
);
case FieldType.MultiSelect:
case FieldType.SingleSelect:
@ -95,7 +95,7 @@ class GridCellControllerBuilder {
cellCache: _cellCache,
cellDataLoader: cellDataLoader,
fieldNotifier: cellFieldNotifier,
cellDataPersistence: CellDataPersistence(cellId: _cellId),
cellDataPersistence: TextCellDataPersistence(cellId: _cellId),
);
case FieldType.URL:
@ -108,7 +108,7 @@ class GridCellControllerBuilder {
cellCache: _cellCache,
cellDataLoader: cellDataLoader,
fieldNotifier: cellFieldNotifier,
cellDataPersistence: CellDataPersistence(cellId: _cellId),
cellDataPersistence: TextCellDataPersistence(cellId: _cellId),
);
}
throw UnimplementedError;
@ -123,14 +123,14 @@ class GridCellControllerBuilder {
/// Generic D represents the type of data that will be saved to the disk
///
// ignore: must_be_immutable
class IGridCellController<T, D> extends Equatable {
class GridCellController<T, D> extends Equatable {
final GridCellIdentifier cellId;
final GridCellCache _cellsCache;
final GridCellCacheKey _cacheKey;
final FieldService _fieldService;
final GridCellFieldNotifier _fieldNotifier;
final GridCellDataLoader<T> _cellDataLoader;
final IGridCellDataPersistence<D> _cellDataPersistence;
final GridCellDataPersistence<D> _cellDataPersistence;
CellListener? _cellListener;
CellDataNotifier<T?>? _cellDataNotifier;
@ -141,12 +141,12 @@ class IGridCellController<T, D> extends Equatable {
Timer? _saveDataOperation;
bool _isDispose = false;
IGridCellController({
GridCellController({
required this.cellId,
required GridCellCache cellCache,
required GridCellFieldNotifier fieldNotifier,
required GridCellDataLoader<T> cellDataLoader,
required IGridCellDataPersistence<D> cellDataPersistence,
required GridCellDataPersistence<D> cellDataPersistence,
}) : _cellsCache = cellCache,
_cellDataLoader = cellDataLoader,
_cellDataPersistence = cellDataPersistence,

View File

@ -5,14 +5,14 @@ abstract class IGridCellDataConfig {
bool get reloadOnFieldChanged;
}
abstract class IGridCellDataParser<T> {
abstract class GridCellDataParser<T> {
T? parserData(List<int> data);
}
class GridCellDataLoader<T> {
final CellService service = CellService();
final GridCellIdentifier cellId;
final IGridCellDataParser<T> parser;
final GridCellDataParser<T> parser;
final bool reloadOnFieldChanged;
GridCellDataLoader({
@ -43,7 +43,7 @@ class GridCellDataLoader<T> {
}
}
class StringCellDataParser implements IGridCellDataParser<String> {
class StringCellDataParser implements GridCellDataParser<String> {
@override
String? parserData(List<int> data) {
final s = utf8.decode(data);
@ -51,7 +51,7 @@ class StringCellDataParser implements IGridCellDataParser<String> {
}
}
class DateCellDataParser implements IGridCellDataParser<DateCellDataPB> {
class DateCellDataParser implements GridCellDataParser<DateCellDataPB> {
@override
DateCellDataPB? parserData(List<int> data) {
if (data.isEmpty) {
@ -62,7 +62,7 @@ class DateCellDataParser implements IGridCellDataParser<DateCellDataPB> {
}
class SelectOptionCellDataParser
implements IGridCellDataParser<SelectOptionCellDataPB> {
implements GridCellDataParser<SelectOptionCellDataPB> {
@override
SelectOptionCellDataPB? parserData(List<int> data) {
if (data.isEmpty) {
@ -72,7 +72,7 @@ class SelectOptionCellDataParser
}
}
class URLCellDataParser implements IGridCellDataParser<URLCellDataPB> {
class URLCellDataParser implements GridCellDataParser<URLCellDataPB> {
@override
URLCellDataPB? parserData(List<int> data) {
if (data.isEmpty) {

View File

@ -2,14 +2,14 @@ part of 'cell_service.dart';
/// Save the cell data to disk
/// You can extend this class to do custom operations. For example, the DateCellDataPersistence.
abstract class IGridCellDataPersistence<D> {
abstract class GridCellDataPersistence<D> {
Future<Option<FlowyError>> save(D data);
}
class CellDataPersistence implements IGridCellDataPersistence<String> {
class TextCellDataPersistence implements GridCellDataPersistence<String> {
final GridCellIdentifier cellId;
CellDataPersistence({
TextCellDataPersistence({
required this.cellId,
});
final CellService _cellService = CellService();
@ -33,8 +33,7 @@ class CalendarData with _$CalendarData {
_CalendarData;
}
class DateCellDataPersistence
implements IGridCellDataPersistence<CalendarData> {
class DateCellDataPersistence implements GridCellDataPersistence<CalendarData> {
final GridCellIdentifier cellId;
DateCellDataPersistence({
required this.cellId,

View File

@ -65,7 +65,7 @@ class CheckboxCellState with _$CheckboxCellState {
required bool isSelected,
}) = _CheckboxCellState;
factory CheckboxCellState.initial(GridCellController context) {
factory CheckboxCellState.initial(GridTextCellController context) {
return CheckboxCellState(isSelected: _isSelected(context.getCellData()));
}
}

View File

@ -82,7 +82,7 @@ class NumberCellState with _$NumberCellState {
required String cellContent,
}) = _NumberCellState;
factory NumberCellState.initial(GridCellController context) {
factory NumberCellState.initial(GridTextCellController context) {
return NumberCellState(
cellContent: context.getCellData() ?? "",
);

View File

@ -6,7 +6,7 @@ import 'cell_service/cell_service.dart';
part 'text_cell_bloc.freezed.dart';
class TextCellBloc extends Bloc<TextCellEvent, TextCellState> {
final GridCellController cellController;
final GridTextCellController cellController;
void Function()? _onCellChangedFn;
TextCellBloc({
required this.cellController,
@ -66,7 +66,8 @@ class TextCellState with _$TextCellState {
required String content,
}) = _TextCellState;
factory TextCellState.initial(GridCellController context) => TextCellState(
factory TextCellState.initial(GridTextCellController context) =>
TextCellState(
content: context.getCellData() ?? "",
);
}

View File

@ -652,7 +652,8 @@ class GridFieldController {
}
}
class GridRowFieldNotifierImpl extends IGridRowFieldNotifier {
class GridRowFieldNotifierImpl extends RowChangesetNotifierForward
with RowCacheDelegate {
final GridFieldController _cache;
OnReceiveUpdateFields? _onChangesetFn;
OnReceiveFields? _onFieldFn;

View File

@ -13,11 +13,11 @@ part 'row_bloc.freezed.dart';
class RowBloc extends Bloc<RowEvent, RowState> {
final RowFFIService _rowService;
final GridRowDataController _dataController;
final RowDataController _dataController;
RowBloc({
required RowInfo rowInfo,
required GridRowDataController dataController,
required RowDataController dataController,
}) : _rowService = RowFFIService(gridId: rowInfo.gridId),
_dataController = dataController,
super(RowState.initial(rowInfo, dataController.loadData())) {

View File

@ -12,10 +12,13 @@ part 'row_cache.freezed.dart';
typedef RowUpdateCallback = void Function();
abstract class IGridRowFieldNotifier {
UnmodifiableListView<FieldInfo> get fields;
abstract class RowChangesetNotifierForward {
void onRowFieldsChanged(VoidCallback callback);
void onRowFieldChanged(void Function(FieldInfo) callback);
}
abstract class RowCacheDelegate {
UnmodifiableListView<FieldInfo> get fields;
void onRowDispose();
}
@ -33,8 +36,8 @@ class GridRowCache {
final RowList _rowList = RowList();
final GridCellCache _cellCache;
final IGridRowFieldNotifier _fieldNotifier;
final _RowChangesetNotifier _rowChangeReasonNotifier;
final RowCacheDelegate _delegate;
final RowChangesetNotifier _rowChangeReasonNotifier;
UnmodifiableListView<RowInfo> get visibleRows {
var visibleRows = [..._rowList.rows];
@ -46,10 +49,11 @@ class GridRowCache {
GridRowCache({
required this.gridId,
required this.rows,
required IGridRowFieldNotifier notifier,
required RowChangesetNotifierForward notifier,
required RowCacheDelegate delegate,
}) : _cellCache = GridCellCache(gridId: gridId),
_rowChangeReasonNotifier = _RowChangesetNotifier(),
_fieldNotifier = notifier {
_rowChangeReasonNotifier = RowChangesetNotifier(),
_delegate = delegate {
//
notifier.onRowFieldsChanged(() => _rowChangeReasonNotifier
.receive(const RowsChangedReason.fieldDidChange()));
@ -65,7 +69,7 @@ class GridRowCache {
}
Future<void> dispose() async {
_fieldNotifier.onRowDispose();
_delegate.onRowDispose();
_rowChangeReasonNotifier.dispose();
await _cellCache.dispose();
}
@ -225,7 +229,7 @@ class GridRowCache {
GridCellMap _makeGridCells(String rowId, RowPB? row) {
// ignore: prefer_collection_literals
var cellDataMap = GridCellMap();
for (final field in _fieldNotifier.fields) {
for (final field in _delegate.fields) {
if (field.visibility) {
cellDataMap[field.id] = GridCellIdentifier(
rowId: rowId,
@ -264,16 +268,16 @@ class GridRowCache {
RowInfo buildGridRow(RowPB rowPB) {
return RowInfo(
gridId: gridId,
fields: _fieldNotifier.fields,
fields: _delegate.fields,
rowPB: rowPB,
);
}
}
class _RowChangesetNotifier extends ChangeNotifier {
class RowChangesetNotifier extends ChangeNotifier {
RowsChangedReason reason = const InitialListState();
_RowChangesetNotifier();
RowChangesetNotifier();
void receive(RowsChangedReason newReason) {
reason = newReason;

View File

@ -7,13 +7,13 @@ import 'row_cache.dart';
typedef OnRowChanged = void Function(GridCellMap, RowsChangedReason);
class GridRowDataController extends GridCellBuilderDelegate {
class RowDataController extends GridCellBuilderDelegate {
final RowInfo rowInfo;
final List<VoidCallback> _onRowChangedListeners = [];
final GridFieldController _fieldController;
final GridRowCache _rowCache;
GridRowDataController({
RowDataController({
required this.rowInfo,
required GridFieldController fieldController,
required GridRowCache rowCache,

View File

@ -7,7 +7,7 @@ import 'row_data_controller.dart';
part 'row_detail_bloc.freezed.dart';
class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
final GridRowDataController dataController;
final RowDataController dataController;
RowDetailBloc({
required this.dataController,

View File

@ -18,10 +18,12 @@ class GridViewCache {
required this.gridId,
required GridFieldController fieldController,
}) : _gridViewListener = GridViewListener(viewId: gridId) {
final delegate = GridRowFieldNotifierImpl(fieldController);
_rowCache = GridRowCache(
gridId: gridId,
rows: [],
notifier: GridRowFieldNotifierImpl(fieldController),
notifier: delegate,
delegate: delegate,
);
_gridViewListener.start(

View File

@ -275,7 +275,7 @@ class _GridRowsState extends State<_GridRows> {
final fieldController =
context.read<GridBloc>().gridController.fieldController;
final dataController = GridRowDataController(
final dataController = RowDataController(
rowInfo: rowInfo,
fieldController: fieldController,
rowCache: rowCache,
@ -308,7 +308,7 @@ class _GridRowsState extends State<_GridRows> {
GridRowCache rowCache,
GridCellBuilder cellBuilder,
) {
final dataController = GridRowDataController(
final dataController = RowDataController(
rowInfo: rowInfo,
fieldController: fieldController,
rowCache: rowCache,

View File

@ -20,7 +20,7 @@ import 'package:easy_localization/easy_localization.dart';
class GridRowWidget extends StatefulWidget {
final RowInfo rowInfo;
final GridRowDataController dataController;
final RowDataController dataController;
final GridCellBuilder cellBuilder;
final void Function(BuildContext, GridCellBuilder) openDetailPage;

View File

@ -24,7 +24,7 @@ import '../header/field_cell.dart';
import '../header/field_editor.dart';
class RowDetailPage extends StatefulWidget with FlowyOverlayDelegate {
final GridRowDataController dataController;
final RowDataController dataController;
final GridCellBuilder cellBuilder;
const RowDetailPage({

View File

@ -152,7 +152,7 @@ void _resolveGridDeps(GetIt getIt) {
(data, _) => FieldActionSheetBloc(fieldCellContext: data),
);
getIt.registerFactoryParam<TextCellBloc, GridCellController, void>(
getIt.registerFactoryParam<TextCellBloc, GridTextCellController, void>(
(context, _) => TextCellBloc(
cellController: context,
),
@ -165,7 +165,7 @@ void _resolveGridDeps(GetIt getIt) {
),
);
getIt.registerFactoryParam<NumberCellBloc, GridCellController, void>(
getIt.registerFactoryParam<NumberCellBloc, GridTextCellController, void>(
(context, _) => NumberCellBloc(
cellController: context,
),
@ -177,7 +177,7 @@ void _resolveGridDeps(GetIt getIt) {
),
);
getIt.registerFactoryParam<CheckboxCellBloc, GridCellController, void>(
getIt.registerFactoryParam<CheckboxCellBloc, GridTextCellController, void>(
(cellData, _) => CheckboxCellBloc(
service: CellService(),
cellController: cellData,

View File

@ -97,7 +97,7 @@ class BoardTestContext {
return editorBloc;
}
Future<IGridCellController> makeCellController(String fieldId) async {
Future<GridCellController> makeCellController(String fieldId) async {
final builder = await makeCellControllerBuilder(fieldId);
return builder.build();
}
@ -109,7 +109,7 @@ class BoardTestContext {
final rowCache = _boardDataController.rowCache;
final fieldController = _boardDataController.fieldController;
final rowDataController = GridRowDataController(
final rowDataController = RowDataController(
rowInfo: rowInfo,
fieldController: fieldController,
rowCache: rowCache,

View File

@ -54,7 +54,7 @@ class GridTestContext {
return editorBloc;
}
Future<IGridCellController> makeCellController(
Future<GridCellController> makeCellController(
String fieldId, int rowIndex) async {
final builder = await makeCellControllerBuilder(fieldId, rowIndex);
return builder.build();
@ -68,7 +68,7 @@ class GridTestContext {
final rowCache = gridController.rowCache;
final fieldController = gridController.fieldController;
final rowDataController = GridRowDataController(
final rowDataController = RowDataController(
rowInfo: rowInfo,
fieldController: fieldController,
rowCache: rowCache,
@ -131,19 +131,20 @@ class GridTestContext {
return cellController;
}
Future<GridCellController> makeTextCellController(int rowIndex) async {
Future<GridTextCellController> makeTextCellController(int rowIndex) async {
final field = fieldContexts
.firstWhere((element) => element.fieldType == FieldType.RichText);
final cellController =
await makeCellController(field.id, rowIndex) as GridCellController;
await makeCellController(field.id, rowIndex) as GridTextCellController;
return cellController;
}
Future<GridCellController> makeCheckboxCellController(int rowIndex) async {
Future<GridTextCellController> makeCheckboxCellController(
int rowIndex) async {
final field = fieldContexts
.firstWhere((element) => element.fieldType == FieldType.Checkbox);
final cellController =
await makeCellController(field.id, rowIndex) as GridCellController;
await makeCellController(field.id, rowIndex) as GridTextCellController;
return cellController;
}
}