YesPlayMusic/packages/web/states/player.ts

19 lines
499 B
TypeScript
Raw Normal View History

2022-07-11 11:06:41 +08:00
import { Player } from '@/web/utils/player'
import { proxy, subscribe } from 'valtio'
const playerInLocalStorage = localStorage.getItem('player')
const player = proxy(new Player())
player.init((playerInLocalStorage && JSON.parse(playerInLocalStorage)) || {})
subscribe(player, () => {
localStorage.setItem('player', JSON.stringify(player))
})
if (import.meta.env.DEV) {
// eslint-disable-next-line @typescript-eslint/no-extra-semi
;(window as any).player = player
}
export default player