conf icon indicating copy to clipboard operation
conf copied to clipboard

How to handle arrays?

Open bloodchen opened this issue 4 years ago • 4 comments

Let's say I have a config

{
   "items":[ {"name":"abc"},{"name":"dadd"}]
}

How can I add an item to items array?

Thanks

bloodchen avatar Apr 29 '20 01:04 bloodchen

There's currently no nice way to do this. You'll have to do something like:

store.set('items', [...store.get('items'), newItem]);

I plan to add a convenience method for this. See: https://github.com/sindresorhus/electron-store/issues/52

sindresorhus avatar Apr 29 '20 02:04 sindresorhus

@sindresorhus Doesn't this cause performance issues when the array is big?

Nisthar avatar Jul 23 '20 09:07 Nisthar

Only for huge arrays, and you should not store huge chunks of data in conf anyway.

sindresorhus avatar Jul 23 '20 09:07 sindresorhus

For anyone wanting to work on this, see the initial attempt and feedback in: https://github.com/sindresorhus/conf/pull/124

sindresorhus avatar Apr 19 '21 19:04 sindresorhus