Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can v2 split exported type into multiple file #127

Open
mslxl opened this issue Aug 26, 2024 · 1 comment
Open

Can v2 split exported type into multiple file #127

mslxl opened this issue Aug 26, 2024 · 1 comment

Comments

@mslxl
Copy link

mslxl commented Aug 26, 2024

In v1, I can use two export statement to export these commands to 2 file:

 ts::export(collect_types![greet, greet2, greet3], "../src/greet.ts").unwrap();
 ts::export(collect_types![hello, hello2, hello3], "../src/hello.ts").unwrap();

and then register them in tauri.

But in V2, I noticed the commands function of Builder will override old value. Is there any new way to split these exports to multiple file now?

@oscartbeaumont
Copy link
Member

oscartbeaumont commented Aug 26, 2024

It is not official supported but it should continue the function the same as in v1 like you showed above. With the downside being that what you showed only handle types.

The bigger problem with supporting this is that Tauri's generate_handler returns a single function which internally dispatches to each of the registered commands. Tauri Specta can't "see inside" that function so we can easily merge mutliple set of commands.

I suspect it might be possible to create a wrapper function to dispatch to multiple inner functions but i've gotta check exactly how Tauri works internlly cause doing so is not really intended and possible not even semver safe.

We should keep this issue though and I will revisit it when I get some time cause we could surely do better.

Also you could possbile look into using Tauri Specta in a plugin as a solution. The plugin and the app can generate different bindings files and Tauri lets them each register their own commands (although the plugin ones will be scoped I think).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants