43 lines
1.1 KiB
Rust
Raw Normal View History

2021-07-23 08:14:45 +08:00
use crate::{
errors::EditorError,
event::EditorEvent,
handlers::*,
services::{
doc_controller::DocController,
file_manager::{FileManager, FileManagerConfig},
},
2021-07-23 08:14:45 +08:00
};
use flowy_database::DBConnection;
2021-07-22 22:26:38 +08:00
use flowy_dispatch::prelude::*;
2021-07-23 15:00:13 +08:00
use std::sync::Arc;
use tokio::sync::RwLock;
2021-07-22 22:26:38 +08:00
2021-07-23 08:14:45 +08:00
pub trait EditorDatabase: Send + Sync {
fn db_connection(&self) -> Result<DBConnection, EditorError>;
}
pub struct EditorConfig {
root: String,
}
impl EditorConfig {
pub fn new(root: &str) -> Self {
Self {
root: root.to_owned(),
}
}
}
pub fn create(database: Arc<dyn EditorDatabase>, config: EditorConfig) -> Module {
let file_manager = RwLock::new(FileManager::new(FileManagerConfig::new(&config.root)));
let doc_controller = DocController::new(database);
2021-07-22 22:26:38 +08:00
Module::new()
.name("Flowy-Editor")
.data(file_manager)
.data(doc_controller)
2021-07-22 22:26:38 +08:00
.event(EditorEvent::CreateDoc, create_doc)
.event(EditorEvent::UpdateDoc, update_doc)
.event(EditorEvent::ReadDoc, read_doc)
2021-07-22 22:26:38 +08:00
}