sindresorhus / electron-store

Simple data persistence for your Electron app or module - Save and load user preferences, app state, cache, etc
MIT License
4.61k stars 150 forks source link

Store.clear() clears ALL stores #243

Open vothvovo opened 1 year ago

vothvovo commented 1 year ago

Is this intended? I feel like it is unintuitive.

pierretusseau commented 1 year ago

Yes as explained in the README :

.reset(...keys)

Reset items to their default values, as defined by the defaults or schema option.

Use .clear() to reset all items.

sindresorhus commented 1 year ago

No, it clears the current store, as you can see here: https://github.com/sindresorhus/conf/blob/92320d7e2c9db2c56b05dd654c3a248a635598d2/source/index.ts#L285-L291

JoanVicens commented 6 months ago

I think the problem @vothvovo faced is that when you create 2 different stores they will overwrite each other. I assume it's because they share the same config.json file. I tried it myself on this demo project to validate it.

const Store = require('electron-store');

const store1 = new Store();
const store2 = new Store();

store1.set('unicorn', '🦄');
store2.set('unicorn', '🦄');

console.log(store1.get('unicorn'));
//=> '🦄'
console.log(store2.get('unicorn'));
//=> '🦄'

store1.clear();

console.log(store1.get('unicorn'));
//=> undefined
console.log(store2.get('unicorn'));
//=> undefined