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())
原文地址:https://www.cnblogs.com/eric-share/p/15857202.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。