mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-29 12:06:01 +02:00
rename createOrLoad to newOrExisting
This commit is contained in:
@@ -117,7 +117,7 @@ async fn create_store<R: Runtime>(
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn create_or_load<R: Runtime>(
|
||||
async fn new_or_existing<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
store_state: State<'_, StoreState>,
|
||||
path: PathBuf,
|
||||
@@ -133,7 +133,7 @@ async fn create_or_load<R: Runtime>(
|
||||
serialize_fn_name,
|
||||
deserialize_fn_name,
|
||||
)?;
|
||||
let (_, rid) = builder.create_or_load_inner()?;
|
||||
let (_, rid) = builder.new_or_existing_inner()?;
|
||||
Ok(rid)
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ pub trait StoreExt<R: Runtime> {
|
||||
/// tauri::Builder::default()
|
||||
/// .plugin(tauri_plugin_store::Builder::default().build())
|
||||
/// .setup(|app| {
|
||||
/// let store = app.store_builder("users.json").auto_save(Duration::from_secs(1)).create_or_load()?;
|
||||
/// let store = app.store_builder("users.json").auto_save(Duration::from_secs(1)).new_or_existing()?;
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
@@ -328,7 +328,7 @@ pub trait StoreExt<R: Runtime> {
|
||||
impl<R: Runtime, T: Manager<R>> StoreExt<R> for T {
|
||||
fn store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> {
|
||||
let path = path.as_ref();
|
||||
StoreBuilder::new(self.app_handle(), path).create_or_load()
|
||||
StoreBuilder::new(self.app_handle(), path).new_or_existing()
|
||||
}
|
||||
|
||||
fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> {
|
||||
@@ -451,7 +451,7 @@ impl<R: Runtime> Builder<R> {
|
||||
/// tauri::Builder::default()
|
||||
/// .plugin(tauri_plugin_store::Builder::default().build())
|
||||
/// .setup(|app| {
|
||||
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin").create_or_load()?;
|
||||
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin").new_or_existing()?;
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
@@ -459,7 +459,7 @@ impl<R: Runtime> Builder<R> {
|
||||
plugin::Builder::new("store")
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
create_store,
|
||||
create_or_load,
|
||||
new_or_existing,
|
||||
get_store,
|
||||
close_store,
|
||||
set,
|
||||
|
||||
+10
-10
@@ -79,7 +79,7 @@ impl<R: Runtime> StoreBuilder<R> {
|
||||
///
|
||||
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin")
|
||||
/// .defaults(defaults)
|
||||
/// .create_or_load()?;
|
||||
/// .new_or_existing()?;
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
@@ -97,7 +97,7 @@ impl<R: Runtime> StoreBuilder<R> {
|
||||
/// .setup(|app| {
|
||||
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin")
|
||||
/// .default("foo".to_string(), "bar")
|
||||
/// .create_or_load()?;
|
||||
/// .new_or_existing()?;
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
@@ -119,7 +119,7 @@ impl<R: Runtime> StoreBuilder<R> {
|
||||
/// .setup(|app| {
|
||||
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
|
||||
/// .serialize(|cache| serde_json::to_vec(&cache).map_err(Into::into))
|
||||
/// .create_or_load()?;
|
||||
/// .new_or_existing()?;
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
@@ -137,7 +137,7 @@ impl<R: Runtime> StoreBuilder<R> {
|
||||
/// .setup(|app| {
|
||||
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
|
||||
/// .deserialize(|bytes| serde_json::from_slice(&bytes).map_err(Into::into))
|
||||
/// .create_or_load()?;
|
||||
/// .new_or_existing()?;
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
@@ -155,7 +155,7 @@ impl<R: Runtime> StoreBuilder<R> {
|
||||
/// .setup(|app| {
|
||||
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
|
||||
/// .auto_save(std::time::Duration::from_millis(100))
|
||||
/// .create_or_load()?;
|
||||
/// .new_or_existing()?;
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
@@ -217,7 +217,7 @@ impl<R: Runtime> StoreBuilder<R> {
|
||||
/// tauri::Builder::default()
|
||||
/// .plugin(tauri_plugin_store::Builder::default().build())
|
||||
/// .setup(|app| {
|
||||
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").create_or_load()?;
|
||||
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").new_or_existing()?;
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
@@ -241,16 +241,16 @@ impl<R: Runtime> StoreBuilder<R> {
|
||||
/// tauri::Builder::default()
|
||||
/// .plugin(tauri_plugin_store::Builder::default().build())
|
||||
/// .setup(|app| {
|
||||
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").create_or_load();
|
||||
/// let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").new_or_existing();
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// ```
|
||||
pub fn create_or_load(self) -> crate::Result<Arc<Store<R>>> {
|
||||
let (store, _) = self.create_or_load_inner()?;
|
||||
pub fn new_or_existing(self) -> crate::Result<Arc<Store<R>>> {
|
||||
let (store, _) = self.new_or_existing_inner()?;
|
||||
Ok(store)
|
||||
}
|
||||
|
||||
pub(crate) fn create_or_load_inner(self) -> crate::Result<(Arc<Store<R>>, ResourceId)> {
|
||||
pub(crate) fn new_or_existing_inner(self) -> crate::Result<(Arc<Store<R>>, ResourceId)> {
|
||||
{
|
||||
let state = self.app.state::<StoreState>();
|
||||
let stores = state.stores.lock().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user