fork from scoresaber-reloaded
This commit is contained in:
34
src/stores/http/http-player-store.js
Normal file
34
src/stores/http/http-player-store.js
Normal file
@ -0,0 +1,34 @@
|
||||
import createHttpStore from './http-store';
|
||||
import playerApiClient from '../../network/clients/scoresaber/player/api'
|
||||
|
||||
export default (playerId = null, initialState = null, initialStateType = 'initial') => {
|
||||
let currentPlayerId = playerId;
|
||||
|
||||
const onNewData = ({fetchParams}) => {
|
||||
currentPlayerId = fetchParams?.playerId ?? null;
|
||||
}
|
||||
|
||||
const httpStore = createHttpStore(
|
||||
playerApiClient,
|
||||
playerId ? {playerId} : null,
|
||||
initialState,
|
||||
{
|
||||
onInitialized: onNewData,
|
||||
onAfterStateChange: onNewData,
|
||||
},
|
||||
initialStateType,
|
||||
);
|
||||
|
||||
const fetch = async (playerId = currentPlayerId, force = false) => {
|
||||
if (!playerId || (playerId === currentPlayerId && !force)) return false;
|
||||
|
||||
return httpStore.fetch({playerId}, force, playerApiClient);
|
||||
}
|
||||
|
||||
return {
|
||||
...httpStore,
|
||||
fetch,
|
||||
getPlayerId: () => currentPlayerId,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user