diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2022-11-29 17:12:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-29 17:12:45 +0100 |
commit | e3237e8cb95424da5f1ae8d1f48805a1b6760a79 (patch) | |
tree | 7877586c7f978b853e40970f16994315f3dbb393 | |
parent | 7f49d533bf68e563a24099ec2492e18599f19671 (diff) | |
download | FlightCore-e3237e8cb95424da5f1ae8d1f48805a1b6760a79.tar.gz FlightCore-e3237e8cb95424da5f1ae8d1f48805a1b6760a79.zip |
docs: Improve developer documentation (#88)
* docs: Add persistent store section heading
* docs: Document interaction frontend<->backend
* docs: Mention Element Plus component library
-rw-r--r-- | docs/DEVELOPMENT.md | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index a003aa89..c6e8301e 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -60,6 +60,69 @@ Note that you can adjust the behaviour of Tauri windows in `tauri.conf.json`, e. ## Docs +### Frontend styling + +For Vue components FlightCore uses the [Element Plus](https://element-plus.org/) library. A list of available components can be found [here](https://element-plus.org/en-US/component/button.html). + +### Interacting between frontend and backend + +The main way the frontend calls the backend is via the `invoke()` function provided by Tauri. + +So assuming you have a backend function + +```Rust +fn my_func(some_string: String, some_int: u32) {} +``` + +You can call it from the frontend with: + +```Typescript +await invoke("my_func", { someString: "Hello, World!", someInt: random_int }) +``` + +Note the change between `snake_case` and `camelCase` in the function argument names. This is imposed by Tauri. + +For returning values after the function call using the `Result<T, E>` type in Rust is recommended. + +This means you'll have a function + +```Rust +fn other_func() -> Result<u32, String> {} +``` + +which returns `Result<u32, String>` + +Now in the frontend when calling it you can for example + +```Typescript +await invoke("other_func") + .then((message) => { + // Success + console.log(`Call returned: ${message}`) + }) + .catch((error) => { + // Error + console.log(error) + }); +``` + +but also + +```Typescript +// Store return in `result` on success +let result = await invoke("other_func") + .catch((error) => { + // Error + console.log(error) + }); +``` + +For more info, see the Tauri docs: https://tauri.app/v1/guides/features/command/ + +For periodic calls between backend and frontend you can use events. See the Tauri docs here: https://tauri.app/v1/guides/features/events/ + +### Persistent store + In regards to storing persistent data, FlightCore uses [`tauri-plugin-store`](https://github.com/tauri-apps/tauri-plugin-store). It's a key-value store accessed in frontend to load and store small amounts of data. The goal is to store as little data in there as possible and instead get the necessary info on app launch. |