jasonmerino / react-native-simple-store

A minimalistic wrapper around React Native's AsyncStorage.

Home Page:https://www.npmjs.com/package/react-native-simple-store

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update or Create function

ciaranschutte opened this issue · comments

Would a update or create function call be of use?
For instance if I want to update an item if it exists already, else create it.

I'd do something like this, and yes I tested this works:

OfflineStore.update(OFFLINE_OBJECT_KEY, someObject)
.catch(error => {
    // NOTE: expect this log to appear only once
    console.log(error)
    // Means First time saving
    OfflineStore.save(OFFLINE_OBJECT_KEY, someObject)
    .catch(err => console.log(err))
})

@ciaranschutte so you are wondering about adding functionality to the .update function which will create whatever value you pass to it if there is no value already stored for the given key? I could see adding this in for that function to make it match the .push function's functionality a bit more.

Closing due to inactivity. If anyone wants to further pursue this conversation comment here and we can open the issue back up.