Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recover default value #80

Closed
MrAmericanMike opened this issue Jul 25, 2019 · 9 comments · Fixed by #84
Closed

Recover default value #80

MrAmericanMike opened this issue Jul 25, 2019 · 9 comments · Fixed by #84
Labels
enhancement 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted

Comments

@MrAmericanMike
Copy link

MrAmericanMike commented Jul 25, 2019

Issuehunt badges

I know the "get" method has an argument that is the default value to return in case the item doesn't exists.

Is there a way to get that value, even if the item exists? Or I would have to delete the key and call get on it?


IssueHunt Summary

husek husek has been rewarded.

Backers (Total: $40.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

@sindresorhus
Copy link
Owner

What is your use-case? It would be helpful to know what specifically you need it for.

@MrAmericanMike
Copy link
Author

For example a value that a user is changing on some configs from default 40 to let's say 77 and I want to have a button so the user can "Reset to default" and make that field 40 again.

@sindresorhus
Copy link
Owner

I agree. I think it could be useful with a store.reset(key) method.

@MrAmericanMike
Copy link
Author

Thanks. Glad you liked the idea ;)

@issuehunt-oss
Copy link

issuehunt-oss bot commented Sep 9, 2019

@issuehunt has funded $40.00 to this issue.


@issuehunt-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label Sep 9, 2019
@amanharwara
Copy link

Any updates on when this is going to get implemented?

@MrAmericanMike
Copy link
Author

Any updates on when this is going to get implemented?

I believe this is already implemented

#84

I will be doing some tests tomorrow, but I believe it's all done ;)

@MrAmericanMike
Copy link
Author

MrAmericanMike commented Oct 25, 2019

Ok so I have run a simple test, and I it's working.
We need to set the defaults in an "schema" https://github.com/sindresorhus/conf

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

const schema = {
    name: {
        type: 'string',
        default: 'Hola'
    }
};

const store = new Store({ schema });

let value = store.get('name');

console.log(value);

store.set('name', 'Manola');

value = store.get('name');
console.log(value);

store.reset('name');

value = store.get('name');
console.log(value);

Output shows

Hola
Manola
Hola

@issuehunt-oss
Copy link

issuehunt-oss bot commented Nov 17, 2019

@sindresorhus has rewarded $36.00 to @husek. See it on IssueHunt

  • 💰 Total deposit: $40.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $4.00

@issuehunt-oss issuehunt-oss bot added 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt and removed 💵 Funded on Issuehunt This issue has been funded on Issuehunt labels Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants