electron-store icon indicating copy to clipboard operation
electron-store copied to clipboard

remove storeInstance.__internal__ from getters ?

Open alex-drocks opened this issue 5 years ago • 2 comments

Hello @sindresorhus your electron-store library is awesome.

What do you think of the possibility of removing / filtering-out the internal property when getting the instance.store data?

I'm talking about this auto-generated property:

"__internal__": {
    "migrations": {
      "version": "0.9.2"
    }
},

Use case:

            migrations: {
                '>=0.9.2': clientStore => {
                    const clients = Object.values(clientStore.store).filter(value => value.nom);
                    clients.forEach(client => {
                        client.id = client.id ? client.id : uuidv4();
                        clientStore.set(client.nom, client);
                    });
                },
            }

As the example suggests, you get the complete file output when getting the store data so you have to remember filtering out the internal property to avoid unhandled error when accessing the objects. In the example I validate that the value has a .nom property to make sure I'm not trying to do a migration on the internal property.

Could there be something similar to this cleanup function directly in the getters of your library ? Like at the source where you populate the returned data ?

    loadFile(storeInstance) {
        const fileData = storeInstance.store; // reads the json file and returns it as a JS object copy
        delete fileData['__internal__']; //remove useless internal property from the object copy
        return fileData; // return clean object of file data
    },

I hope I make sense, please let me know what you think of that.

Thanks, Alexandre Desroches

alex-drocks avatar Nov 09 '20 23:11 alex-drocks

Yes, that should be done. It's just an oversight that it's available in the .store property.

sindresorhus avatar Nov 10 '20 00:11 sindresorhus

@sindresorhus Nice, thank you!

alex-drocks avatar Nov 10 '20 00:11 alex-drocks