chore: remove row listener from rowbloc

This commit is contained in:
appflowy
2022-04-17 09:46:38 +08:00
parent e647fd0a57
commit 0a19364ea7
13 changed files with 158 additions and 124 deletions

View File

@ -6,11 +6,11 @@ const OBSERVABLE_CATEGORY: &str = "Grid";
pub enum GridNotification {
Unknown = 0,
DidCreateBlock = 11,
DidUpdateGridBlock = 20,
DidUpdateGridRow = 20,
DidUpdateGridField = 21,
DidUpdateRow = 30,
DidUpdateCell = 31,
DidUpdateGridField = 40,
DidUpdateField = 41,
DidUpdateCell = 40,
DidUpdateField = 50,
}
impl std::default::Default for GridNotification {

View File

@ -27,11 +27,11 @@
pub enum GridNotification {
Unknown = 0,
DidCreateBlock = 11,
DidUpdateGridBlock = 20,
DidUpdateGridRow = 20,
DidUpdateGridField = 21,
DidUpdateRow = 30,
DidUpdateCell = 31,
DidUpdateGridField = 40,
DidUpdateField = 41,
DidUpdateCell = 40,
DidUpdateField = 50,
}
impl ::protobuf::ProtobufEnum for GridNotification {
@ -43,11 +43,11 @@ impl ::protobuf::ProtobufEnum for GridNotification {
match value {
0 => ::std::option::Option::Some(GridNotification::Unknown),
11 => ::std::option::Option::Some(GridNotification::DidCreateBlock),
20 => ::std::option::Option::Some(GridNotification::DidUpdateGridBlock),
20 => ::std::option::Option::Some(GridNotification::DidUpdateGridRow),
21 => ::std::option::Option::Some(GridNotification::DidUpdateGridField),
30 => ::std::option::Option::Some(GridNotification::DidUpdateRow),
31 => ::std::option::Option::Some(GridNotification::DidUpdateCell),
40 => ::std::option::Option::Some(GridNotification::DidUpdateGridField),
41 => ::std::option::Option::Some(GridNotification::DidUpdateField),
40 => ::std::option::Option::Some(GridNotification::DidUpdateCell),
50 => ::std::option::Option::Some(GridNotification::DidUpdateField),
_ => ::std::option::Option::None
}
}
@ -56,10 +56,10 @@ impl ::protobuf::ProtobufEnum for GridNotification {
static values: &'static [GridNotification] = &[
GridNotification::Unknown,
GridNotification::DidCreateBlock,
GridNotification::DidUpdateGridBlock,
GridNotification::DidUpdateGridRow,
GridNotification::DidUpdateGridField,
GridNotification::DidUpdateRow,
GridNotification::DidUpdateCell,
GridNotification::DidUpdateGridField,
GridNotification::DidUpdateField,
];
values
@ -89,11 +89,11 @@ impl ::protobuf::reflect::ProtobufValue for GridNotification {
}
static file_descriptor_proto_data: &'static [u8] = b"\
\n\x17dart_notification.proto*\x9c\x01\n\x10GridNotification\x12\x0b\n\
\x07Unknown\x10\0\x12\x12\n\x0eDidCreateBlock\x10\x0b\x12\x16\n\x12DidUp\
dateGridBlock\x10\x14\x12\x10\n\x0cDidUpdateRow\x10\x1e\x12\x11\n\rDidUp\
dateCell\x10\x1f\x12\x16\n\x12DidUpdateGridField\x10(\x12\x12\n\x0eDidUp\
dateField\x10)b\x06proto3\
\n\x17dart_notification.proto*\x9a\x01\n\x10GridNotification\x12\x0b\n\
\x07Unknown\x10\0\x12\x12\n\x0eDidCreateBlock\x10\x0b\x12\x14\n\x10DidUp\
dateGridRow\x10\x14\x12\x16\n\x12DidUpdateGridField\x10\x15\x12\x10\n\
\x0cDidUpdateRow\x10\x1e\x12\x11\n\rDidUpdateCell\x10(\x12\x12\n\x0eDidU\
pdateField\x102b\x06proto3\
";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

View File

@ -3,9 +3,9 @@ syntax = "proto3";
enum GridNotification {
Unknown = 0;
DidCreateBlock = 11;
DidUpdateGridBlock = 20;
DidUpdateGridRow = 20;
DidUpdateGridField = 21;
DidUpdateRow = 30;
DidUpdateCell = 31;
DidUpdateGridField = 40;
DidUpdateField = 41;
DidUpdateCell = 40;
DidUpdateField = 50;
}

View File

@ -2,13 +2,13 @@ use crate::dart_notification::{send_dart_notification, GridNotification};
use crate::manager::GridUser;
use crate::services::block_meta_editor::ClientGridBlockMetaEditor;
use crate::services::persistence::block_index::BlockIndexPersistence;
use crate::services::row::{group_row_orders, make_rows_from_row_metas, GridBlockSnapshot};
use crate::services::row::{group_row_orders, GridBlockSnapshot};
use std::borrow::Cow;
use dashmap::DashMap;
use flowy_error::FlowyResult;
use flowy_grid_data_model::entities::{
CellChangeset, CellMeta, CellNotificationData, FieldMeta, GridBlockMeta, GridBlockMetaChangeset, GridRowsChangeset,
CellChangeset, CellMeta, CellNotificationData, GridBlockMeta, GridBlockMetaChangeset, GridRowsChangeset,
IndexRowOrder, RowMeta, RowMetaChangeset, RowOrder,
};
use flowy_revision::disk::SQLiteGridBlockMetaRevisionPersistence;
@ -76,7 +76,7 @@ impl GridBlockMetaEditorManager {
index_row_order.index = row_index;
let _ = self
.notify_did_update_rows(GridRowsChangeset::insert(block_id, vec![index_row_order]))
.notify_did_update_block(GridRowsChangeset::insert(block_id, vec![index_row_order]))
.await?;
Ok(row_count)
}
@ -98,7 +98,7 @@ impl GridBlockMetaEditorManager {
changesets.push(GridBlockMetaChangeset::from_row_count(&block_id, row_count));
let _ = self
.notify_did_update_rows(GridRowsChangeset::insert(&block_id, inserted_row_orders))
.notify_did_update_block(GridRowsChangeset::insert(&block_id, inserted_row_orders))
.await?;
}
@ -108,19 +108,7 @@ impl GridBlockMetaEditorManager {
pub async fn update_row(&self, changeset: RowMetaChangeset) -> FlowyResult<()> {
let editor = self.get_editor_from_row_id(&changeset.row_id).await?;
let _ = editor.update_row(changeset.clone()).await?;
match editor
.get_row_orders(Some(vec![Cow::Borrowed(&changeset.row_id)]))
.await?
.pop()
{
None => {}
Some(row_order) => {
let block_order_changeset = GridRowsChangeset::update(&editor.block_id, vec![row_order]);
let _ = self.notify_did_update_rows(block_order_changeset).await?;
}
}
let _ = self.notify_did_update_block_row(&changeset.row_id).await?;
Ok(())
}
@ -131,7 +119,7 @@ impl GridBlockMetaEditorManager {
let row_orders = editor.get_row_orders(Some(vec![Cow::Borrowed(&row_id)])).await?;
let _ = editor.delete_rows(vec![Cow::Borrowed(&row_id)]).await?;
let _ = self
.notify_did_update_rows(GridRowsChangeset::delete(&block_id, row_orders))
.notify_did_update_block(GridRowsChangeset::delete(&block_id, row_orders))
.await?;
Ok(())
@ -173,7 +161,7 @@ impl GridBlockMetaEditorManager {
updated_rows: vec![],
};
let _ = self.notify_did_update_rows(notified_changeset).await?;
let _ = self.notify_did_update_block(notified_changeset).await?;
}
}
@ -181,10 +169,8 @@ impl GridBlockMetaEditorManager {
}
pub async fn update_cell(&self, changeset: CellChangeset) -> FlowyResult<()> {
let row_id = changeset.row_id.clone();
let editor = self.get_editor_from_row_id(&row_id).await?;
let row_changeset: RowMetaChangeset = changeset.clone().into();
let _ = editor.update_row(row_changeset).await?;
let _ = self.update_row(row_changeset).await?;
let cell_notification_data = CellNotificationData {
grid_id: changeset.grid_id,
@ -193,6 +179,7 @@ impl GridBlockMetaEditorManager {
content: changeset.data,
};
self.notify_did_update_cell(cell_notification_data).await?;
Ok(())
}
@ -239,8 +226,22 @@ impl GridBlockMetaEditorManager {
Ok(block_cell_metas)
}
async fn notify_did_update_rows(&self, changeset: GridRowsChangeset) -> FlowyResult<()> {
send_dart_notification(&self.grid_id, GridNotification::DidUpdateGridBlock)
async fn notify_did_update_block_row(&self, row_id: &str) -> FlowyResult<()> {
let editor = self.get_editor_from_row_id(row_id).await?;
let row_ids = Some(vec![Cow::Borrowed(&row_id)]);
match editor.get_row_orders(row_ids).await?.pop() {
None => {}
Some(row_order) => {
let block_order_changeset = GridRowsChangeset::update(&editor.block_id, vec![row_order]);
let _ = self.notify_did_update_block(block_order_changeset).await?;
}
}
Ok(())
}
async fn notify_did_update_block(&self, changeset: GridRowsChangeset) -> FlowyResult<()> {
send_dart_notification(&self.grid_id, GridNotification::DidUpdateGridRow)
.payload(changeset)
.send();
Ok(())
@ -253,22 +254,6 @@ impl GridBlockMetaEditorManager {
.send();
Ok(())
}
#[allow(dead_code)]
async fn notify_did_update_row(&self, row_id: &str, field_metas: &[FieldMeta]) -> FlowyResult<()> {
match self.get_row_meta(row_id).await? {
None => {}
Some(row_meta) => {
let row_metas = vec![row_meta];
if let Some(row) = make_rows_from_row_metas(field_metas, &row_metas).pop() {
send_dart_notification(row_id, GridNotification::DidUpdateRow)
.payload(row)
.send();
}
}
}
Ok(())
}
}
async fn make_block_meta_editor_map(

View File

@ -77,7 +77,7 @@ impl ClientGridEditor {
Ok(grid.update_field_meta(changeset, deserializer)?)
})
.await?;
let _ = self.notify_grid_did_update_field(&field_id).await?;
let _ = self.notify_did_update_grid_field(&field_id).await?;
} else {
let _ = self
.modify(|grid| {
@ -87,7 +87,7 @@ impl ClientGridEditor {
Ok(grid.create_field_meta(field_meta, start_field_id)?)
})
.await?;
let _ = self.notify_grid_did_insert_field(&field_id).await?;
let _ = self.notify_did_insert_grid_field(&field_id).await?;
}
Ok(())
@ -114,14 +114,14 @@ impl ClientGridEditor {
.modify(|grid| Ok(grid.update_field_meta(params, json_deserializer)?))
.await?;
let _ = self.notify_grid_did_update_field(&field_id).await?;
let _ = self.notify_did_update_grid_field(&field_id).await?;
Ok(())
}
pub async fn replace_field(&self, field_meta: FieldMeta) -> FlowyResult<()> {
let field_id = field_meta.id.clone();
let _ = self.modify(|pad| Ok(pad.replace_field_meta(field_meta)?)).await?;
let _ = self.notify_grid_did_update_field(&field_id).await?;
let _ = self.notify_did_update_grid_field(&field_id).await?;
Ok(())
}
@ -153,7 +153,7 @@ impl ClientGridEditor {
.modify(|grid| Ok(grid.switch_to_field(field_id, field_type.clone(), type_option_json_builder)?))
.await?;
let _ = self.notify_grid_did_update_field(field_id).await?;
let _ = self.notify_did_update_grid_field(field_id).await?;
Ok(())
}
@ -164,7 +164,7 @@ impl ClientGridEditor {
.modify(|grid| Ok(grid.duplicate_field_meta(field_id, &duplicated_field_id)?))
.await?;
let _ = self.notify_grid_did_insert_field(field_id).await?;
let _ = self.notify_did_insert_grid_field(field_id).await?;
Ok(())
}
@ -462,7 +462,7 @@ impl ClientGridEditor {
}
#[tracing::instrument(level = "trace", skip_all, err)]
async fn notify_grid_did_insert_field(&self, field_id: &str) -> FlowyResult<()> {
async fn notify_did_insert_grid_field(&self, field_id: &str) -> FlowyResult<()> {
if let Some((index, field_meta)) = self.pad.read().await.get_field_meta(field_id) {
let index_field = IndexField::from_field_meta(field_meta, index);
let notified_changeset = GridFieldChangeset::insert(&self.grid_id, vec![index_field]);
@ -472,7 +472,7 @@ impl ClientGridEditor {
}
#[tracing::instrument(level = "trace", skip_all, err)]
async fn notify_grid_did_update_field(&self, field_id: &str) -> FlowyResult<()> {
async fn notify_did_update_grid_field(&self, field_id: &str) -> FlowyResult<()> {
let mut field_metas = self.get_field_metas(Some(vec![field_id])).await?;
debug_assert!(field_metas.len() == 1);