How can I modularize command handler generation? #13085
Replies: 3 comments 1 reply
-
|
Hi,
|
Beta Was this translation helpful? Give feedback.
-
|
Hello, I am also in the same requirement. It would be nice to be able to modularize the commands in the |
Beta Was this translation helpful? Give feedback.
-
|
You cannot concatenate the values returned by For an application-internal module boundary, I would keep the command implementations split by domain and move only the central registry out of // src-tauri/src/commands/mod.rs
pub mod module_1;
pub mod module_2;
pub fn handler()
-> impl Fn(tauri::ipc::Invoke<tauri::Wry>) -> bool + Send + Sync + 'static
{
tauri::generate_handler![
module_1::function_1,
module_1::function_2,
module_2::function_16,
module_2::function_17,
]
}// src-tauri/src/lib.rs
mod commands;
pub fn run() {
tauri::Builder::default()
.invoke_handler(commands::handler())
.run(tauri::generate_context!())
.expect("error while running Tauri application");
}The command functions in the child modules need to be This leaves one registry, which Tauri requires, but removes the large list from the builder setup and keeps implementation ownership in the domain modules. If the modules are genuinely independent subsystems and you want each one to own its own handler registry, model each subsystem as a Tauri plugin instead. References:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
As the title suggests, I am looking to modularize the creation of command handlers so that I don't bloat the Tauri builder setup with a potentially large amount of commands that need to be accessible from the front-end. I know you can't call invoke_handler more than once per a comment on a similar thread from Fabian but I don't want to call it multiple times anyways. I want to just have a way to split the creation of the handlers or a way to make a combination of the two. Ideally it would look something like the following
module_1.rs
module_2.rs
lib.rs
Obviously I'm trivializing some details here for the sake of getting my point across but if anyone knows how to do something similar I'd be forever grateful!
Beta Was this translation helpful? Give feedback.
All reactions