refactor: version 2.0 (React)

This commit is contained in:
qier222 2022-03-13 14:40:38 +08:00
parent 7dad7d810a
commit 950f72d4e8
No known key found for this signature in database
GPG key ID: 9C85007ED905F14D
356 changed files with 7901 additions and 29547 deletions

View file

@ -0,0 +1,36 @@
import { RefObject } from 'react'
import { proxy, subscribe } from 'valtio'
import { devtools } from 'valtio/utils'
import { player as PlayerCore } from '@/utils/player'
interface Store {
uiStates: {
loginPhoneCountryCode: string
}
settings: {
showSidebar: boolean
}
}
const initialState: Store = {
uiStates: {
loginPhoneCountryCode: '+86',
},
settings: {
showSidebar: true,
},
}
const stateInLocalStorage = localStorage.getItem('state')
export const state = proxy<Store>(
(stateInLocalStorage && JSON.parse(stateInLocalStorage)) || initialState
)
subscribe(state, () => {
localStorage.setItem('state', JSON.stringify(state))
})
export const player = proxy(PlayerCore)
// Devtools
devtools(state, 'state')
devtools(player, 'player')