sindresorhus/electron-store

remove storeInstance.__internal__ from getters ?

Open

#151 创建于 2020年11月9日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)JavaScript (4,304 star) (150 fork)batch import
bughelp wanted

描述

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

贡献者指南

remove storeInstance.__internal__ from getters ? · sindresorhus/electron-store#151 | Good First Issue