Questions about patterns #2566
-
Hello everyone. When I was learning tauri, I encountered problems about "patterns". First, I didn't understand the role of "patterns", and second, I didn't understand the usage scenarios of each "pattern". Please advise, if there are simple examples, it would be better. thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Patterns just describe different ways about the way your JS view communicates with the Rust code. And depending on the type of application you want to build, you can choose a pattern. For example one pattern provides methods exposes to JS that are implemented by default in Rust (file system access for example). If your application needs to read a file, you can use that api to do it. I mostly go with the lockdown pattern. It removes all default APIs. If you need access to files you have to write a custom Rust command yourself. In my case it's almost always a database access that returns the data in some way. That way you can restrict what the JS code can do. |
Beta Was this translation helpful? Give feedback.
Patterns just describe different ways about the way your JS view communicates with the Rust code. And depending on the type of application you want to build, you can choose a pattern.
For example one pattern provides methods exposes to JS that are implemented by default in Rust (file system access for example). If your application needs to read a file, you can use that api to do it.
I mostly go with the lockdown pattern. It removes all default APIs. If you need access to files you have to write a custom Rust command yourself. In my case it's almost always a database access that returns the data in some way. That way you can restrict what the JS code can do.