其他分享
首页 > 其他分享> > 封装electron-store

封装electron-store

作者:互联网

const Store = require('electron-store') const { v4: uuidv4 } = require('uuid'); const path = require('path')
class DataStore extends Store {     constructor(settings){         super(settings)         this.tracks =  this.get('tracks') || []     }
    saveTracks(){         this.set('tracks', this.tracks)         return this     }
    getTracks(){         return this.get('tracks') || []     }
    addTracks(tracks){         const trackWithProps = tracks.map((track)=>{             return {                 id: uuidv4(),                 path:track,                 fileName: path.basename(track)             }         }).filter( track => {             const currentTracksPath = this.getTracks().map(track => track.path)             return currentTracksPath.indexOf(track.path) < 0         })
        this.tracks = [...this.tracks,...trackWithProps]         return this.saveTracks()     }
    deleteTrack(deletedId){         this.tracks = this.tracks.filter(item => item.id !== deletedId)         return  this.saveTracks()     }
}
module.exports = DataStore   ---------- const DataStore = require('./renderer/MusicDataStore'); const myStore = new DataStore({   'name': 'Music Data' })      mainWindow.send('getTracks',myStore.getTracks())

标签:const,track,tracks,return,electron,path,封装,DataStore,store
来源: https://www.cnblogs.com/eric-share/p/15857202.html