fork from scoresaber-reloaded

This commit is contained in:
Lee
2023-10-17 21:42:37 +01:00
commit cc884eec07
229 changed files with 31236 additions and 0 deletions

View 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,
}
}