Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upConvenience methods #52
Comments
|
New to using the library and I just tried to push stuff to an array, this would definitely be great to have! The |
|
I disagree about adding any convenience methods at all, as it breaks the SRP. |
|
@asmironov SRP? |
|
@sindresorhus, well, the single responsibility principle. From the SOLID. Electron storing arbitrary data in the json file is one thing, plain and simple. Modifying the data in that file, depending on its structure, is another. It's better not to mix them together. |
|
Will be great to have |
|
I like the the
Another alternative: Have the //BEFORE
const array = store.get('array');
array.find(element => element.title === 'baz').src = 'something';
store.set('array', array);
//AFTER
store.set('some_arr', (array) => {
array.find(element => element.title === 'baz').src = 'something';
return array;
})I agree with @asmironov _"convenience method that makes sense is modify (mutate)" EDIT:
|
|
This could also be useful: Before{
label: 'Auto Hide Menu Bar',
type: 'checkbox',
checked: config.get('autoHideMenuBar'),
click(item, focusedWindow) {
config.set('autoHideMenuBar', item.checked);
focusedWindow.setAutoHideMenuBar(item.checked);
focusedWindow.setMenuBarVisibility(!item.checked);
}
}Afterstore.checkboxMenuItem(
label: 'Auto Hide Menu Bar'
click(item, focusedWindow) {
focusedWindow.setAutoHideMenuBar(item.checked);
focusedWindow.setMenuBarVisibility(!item.checked);
}
)I do this a lot in my apps and it would reduce the boilerplate. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

I propose adding some convenience methods to make common things easier.
What I do most of the time when using
electron-storeis to get a boolean and invert it. For example,store.set('isFoo', !store.get('isFoo')).Would be nice to have:
.toggleBoolean(key)which accepts a key and toggles the boolean..appendToArray(key, newItem)which pushes a new item to the array. (#32).modify(key, mutateCallback)which would give you a callback to modify the value that you then return in the callback:Before:
After:
These methods will require you to specify the
keyin thedefaultsoption, so it would always work. If you try to usetoggleBoolean()and the underlaying value is of a different type, it would throw an error.Any other convenience methods we could add? I'm also interested in feedback on the method names.
*Note: While I opened the issue here, the methods we eventually go for should be added to
conf.