Goodnight!
I need help…
Is it possible to shorten this code? I would like to take all these SET and put it in a line or function. How can I do this?
const storage = this.storage;
const setUrl = await storage.set("url", res.data().url)
const setVersion = await storage.set("version", res.data().version)
const setStoreName = await storage.set("storeName", res.data().storeName)
const setWoocommerceApi = await storage.set('woocommerceApi', res.data().woocommerceApi)
const setWoocommerceSecret = await storage.set('woocommerceSecret', res.data().woocommerceSecret)
Make it one object with all lines as a property and save that one in one save action?
Yes.
I would like to shorten this code.
const storage = this.storage;
const stuffToStore= {
url:res.data().url,
version:res.data().version,
storeName:res.data().storeName,
woocommerceApi:res.data().woocommerceApi,
woocommerceSecret:res.data().woocommerceSecret
}
const setStuffToStore = await storage.set("stuff", stuffToStore)
1 Like
const storage = this.storage;
const stuffToStore= {}
const res=res.data();
['url','version','storeName','woocommerceApi','woocommerceSecret']
.forEach(key=>stuffToStore[key]=res[key])
const setStuffToStore = await storage.set("stuff", stuffToStore)
Thank you very much. God bless you
1 Like